我有一个durandal 2.0 MVC 4项目,想缩小并合并所有javascript文件。
因此,我使用weyland:https://github.com/BlueSpire/Weyland
我按照文档中的说明进行操作,除了没有生成输出文件之外,其他所有方法似乎都可以使用。
这是我的weyland配置:
exports.config = function (weyland) {
weyland.build('main')
.task.jshint({
include: 'App/**/*.js'
})
.task.uglifyjs({
include: ['App/**/*.js', 'Scripts/durandal/**/*.js']
})
.task.rjs({
include: ['App/**/*.{js,html}', 'Scripts/durandal/**/*.js'],
loaderPluginExtensionMaps: {
'.html': 'text'
},
rjs: {
name: '../Scripts/library/almond-custom',
insertRequire: ['main'], //not needed for require
baseUrl: 'App',
wrap: true, //not needed for require
paths: {
'text': '../Scripts/library/text',
'durandal': '../Scripts/durandal',
'plugins': '../Scripts/durandal/plugins',
'transitions': '../Scripts/durandal/transitions',
'knockout': 'empty:',
'jquery': 'empty:',
'validation': 'empty:',
'jquPlugins': '../Scripts/library/plugins',
'lib': '../Scripts/library',
'service': 'services',
'vm': 'viewmodels',
'view': 'views',
'repo': 'repositories',
},
inlineText: true,
optimize: 'none',
pragmas: {
build: true
},
stubModules: ['text'],
keepBuildDir: true,
out: 'main-built.js'
}
});
};
我从Visual Studio获得以下控制台输出:
14> info jshint Linting 15 files.
14> ERR! jshint Found 3 issues while linting App/main.js.
14> info jshint Passed for App/repositories/userRepository.js.
14> info jshint Passed for App/services/security.js.
14> info jshint Passed for App/viewmodels/account/logon.js.
14> ERR! jshint Found 1 issues while linting App/viewmodels/account/template/forg
14> otPassword.js.
14> info jshint Passed for App/viewmodels/error/404error.js.
14> info jshint Passed for App/viewmodels/shared/pageBottom.js.
14> info jshint Passed for App/viewmodels/shared/pageCenter.js.
14> info jshint Passed for App/viewmodels/shared/pageTop.js.
14> info jshint Passed for App/viewmodels/shared/sideControl.js.
14> info jshint Passed for App/viewmodels/shared/table.js.
14> info jshint Passed for App/viewmodels/shell.js.
14> info jshint Passed for App/viewmodels/user/controls.js.
14> info jshint Passed for App/viewmodels/user/index.js.
14> info jshint Passed for App/viewmodels/user/template/userModal.js.
14> info uglifyjs Uglifying 35 files.
14> WARN: Dropping unused function argument key [null:67,66]
14> info uglifyjs Uglified App/main.js.
14> WARN: Dropping unused function argument $ [null:1,88]
14> WARN: Dropping unused function argument data [null:37,28]
14> info uglifyjs Uglified App/repositories/userRepository.js.
14> WARN: Dropping unused function argument thrownError [null:40,74]
14> WARN: Dropping unused function argument ajaxSettings [null:40,60]
14> info uglifyjs Uglified App/services/security.js.
14> WARN: Dropping unused function argument event [null:52,35]
14> WARN: Dropping unused function argument data [null:52,29]
14> info uglifyjs Uglified App/viewmodels/account/logon.js.
14> info uglifyjs Uglified App/viewmodels/account/template/forgotPassword.js.
14> info uglifyjs Uglified App/viewmodels/error/404error.js.
14> info uglifyjs Uglified App/viewmodels/shared/pageBottom.js.
14> info uglifyjs Uglified App/viewmodels/shared/pageCenter.js.
14> info uglifyjs Uglified App/viewmodels/shared/pageTop.js.
14> WARN: Side effects in initialization of unused variable filteredItems [null:4
14> ,8]
14> WARN: Dropping unused variable updateTable [null:8,8]
14> WARN: Dropping unused variable itemClicked [null:52,8]
14> WARN: Dropping unused variable itemActivate [null:62,8]
14> WARN: Dropping unused variable toggleActive [null:64,8]
14> info uglifyjs Uglified App/viewmodels/shared/sideControl.js.
14> WARN: Side effects in initialization of unused variable filteredItems [null:4
14> ,8]
14> WARN: Side effects in initialization of unused variable filtered [null:10,8]
14> WARN: Dropping unused variable filterItems [null:33,8]
14> WARN: Dropping unused variable searchMatch [null:47,8]
14> WARN: Dropping unused function argument settings [null:96,53]
14> WARN: Dropping unused function argument parent [null:96,45]
14> WARN: Dropping unused function argument parent [null:125,33]
14> WARN: Dropping unused function argument view [null:125,27]
14> WARN: Dropping unused function argument action [null:110,51]
14> WARN: Dropping unused function argument koTarget [null:110,41]
14> info uglifyjs Uglified App/viewmodels/shared/table.js.
14> info uglifyjs Uglified App/viewmodels/shell.js.
14> info uglifyjs Uglified App/viewmodels/user/controls.js.
14> WARN: Dropping unused function argument app [null:1,62]
14> WARN: Dropping unused function argument system [null:1,54]
14> info uglifyjs Uglified App/viewmodels/user/index.js.
14> WARN: Dropping unused function argument context [null:13,31]
14> info uglifyjs Uglified App/viewmodels/user/template/userModal.js.
14> WARN: Dropping unused function argument newActivationData [null:562,76]
14> WARN: Dropping unused function argument currentActivationData [null:562,53]
14> info uglifyjs Uglified Scripts/durandal/activator.js.
14> WARN: Dropping unused function argument ko [null:15,170]
14> WARN: Dropping unused function argument schemas [null:59,52]
14> WARN: Dropping unused function argument err [null:61,29]
14> info uglifyjs Uglified Scripts/durandal/app.js.
14> info uglifyjs Uglified Scripts/durandal/binder.js.
14> WARN: Dropping unused function argument element [null:453,46]
14> info uglifyjs Uglified Scripts/durandal/composition.js.
14> info uglifyjs Uglified Scripts/durandal/events.js.
14> WARN: Dropping unused function argument request [null:53,57]
14> WARN: Dropping unused function argument textStatus [null:53,45]
14> WARN: Dropping unused function argument request [null:61,57]
14> WARN: Dropping unused function argument textStatus [null:61,45]
14> WARN: Dropping unused function argument request [null:75,56]
14> WARN: Dropping unused function argument textStatus [null:75,44]
14> WARN: Dropping unused function argument data [null:75,38]
14> info uglifyjs Uglified Scripts/durandal/plugins/authentication.js.
14> WARN: Dropping unused function argument repository [null:76,49]
14> info uglifyjs Uglified Scripts/durandal/plugins/config.js.
14> WARN: Dropping unused function argument e [null:120,43]
14> WARN: Dropping unused function argument e [null:139,29]
14> WARN: Dropping unused function argument e [null:155,28]
14> info uglifyjs Uglified Scripts/durandal/plugins/contextMenu.js.
14> WARN: Side effects in initialization of unused variable width [null:394,16]
14> WARN: Side effects in initialization of unused variable height [null:395,16]
14> info uglifyjs Uglified Scripts/durandal/plugins/dialog.js.
14> info uglifyjs Uglified Scripts/durandal/plugins/history.js.
14> info uglifyjs Uglified Scripts/durandal/plugins/http.js.
14> info uglifyjs Uglified Scripts/durandal/plugins/observable.js.
14> info uglifyjs Uglified Scripts/durandal/plugins/router.js.
14> info uglifyjs Uglified Scripts/durandal/plugins/serializer.js.
14> WARN: Dropping unused function argument request [null:7,49]
14> WARN: Dropping unused function argument textStatus [null:7,37]
14> info uglifyjs Uglified Scripts/durandal/plugins/translation.js.
14> info uglifyjs Uglified Scripts/durandal/plugins/widget.js.
14> WARN: Dropping unused function argument depArray [null:52,59]
14> info uglifyjs Uglified Scripts/durandal/system.js.
14> info uglifyjs Uglified Scripts/durandal/transitions/entrance.js.
14> WARN: Dropping unused function argument err [null:150,59]
14> info uglifyjs Uglified Scripts/durandal/viewEngine.js.
14> WARN: Dropping unused function argument area [null:116,49]
14> info uglifyjs Uglified Scripts/durandal/viewLocator.js.
14> main
14> repo/userRepository
14> service/security
14> info rjs Packaging 49 files.
14> vm/account/logon
14> vm/account/template/forgotPassword
14> vm/error/404error
14> vm/shared/pageBottom
14> vm/shared/pageCenter
14> vm/shared/pageTop
14> vm/shared/sideControl
14> vm/shared/table
14> vm/shell
14> vm/user/controls
14> vm/user/index
14> vm/user/template/userModal
14> text!view/account/logon.html
14> text!view/account/template/forgotPassword.html
14> text!view/error/404error.html
14> text!view/shared/pageBottom.html
14> text!view/shared/pageCenter.html
14> text!view/shared/pageTop.html
14> text!view/shared/sideControl.html
14> text!view/shared/table.html
14> text!view/shell.html
14> text!view/user/controls.html
14> text!view/user/index.html
14> text!view/user/template/sideBarItem.html
14> text!view/user/template/tableItem.html
14> text!view/user/template/userModal.html
14> durandal/activator
14> durandal/app
14> durandal/binder
14> durandal/composition
14> durandal/events
14> plugins/authentication
14> plugins/config
14> plugins/contextMenu
14> plugins/dialog
14> plugins/history
14> plugins/http
14> plugins/observable
14> plugins/router
14> plugins/serializer
14> plugins/translation
14> plugins/widget
14> durandal/system
dransitions/entrance
durandal/viewEngine
durandal/viewLocator
========== Rebuild All: 14 succeeded, 0 failed, 0 skipped ==========
我不知道如何找出问题所在。
最佳答案
解决方案是仅添加刷新almond-custom.js。
我查看了这些更改,显然缺少以下功能:
function onResourceLoad(name, defined, deps){
if(requirejs.onResourceLoad && name){
requirejs.onResourceLoad({defined:defined}, {id:name}, deps);
}
}
无法解释该功能为何不存在的原因,因为它与文件的版本相同。 (0.2.0)。而已。