我的印象是 RequireJS 优化器会查看已定义的依赖项并收集应用程序中所有引用的 js 文件,并将它们捆绑到一个大型 js 文件中。
然后,您就可以在您的 html 脚本包含中引用该单个文件。
但情况似乎并非如此。当我运行它时,我得到一个大文件,但它包含原始 main.js 文件,该文件包含目录结构中文件的路径。
那有什么意义呢?如果需要的所有内容都包含在其中,为什么新的大文件包含自身之外的路径?似乎优化器会重写路径以指向“./”或其他东西。
当我捆绑整个应用程序并在页面中引用它时,我收到有关丢失文件的错误,这些文件包含在大型 js 文件中:
Uncaught object require.js:70
GET http://localhost/ui/js/modules/mod_limeLight.js 404 (Not Found) require.js:729
Uncaught Error: Script error for: mod_limelight
http://requirejs.org/docs/errors.html#scripterror
构建.js:
({
baseUrl: "./src/ui/scripts",
name: "main",
mainConfigFile : "src/ui/scripts/main.js",
out: "dist/ui/scripts/main-built.js"
})
main.js
'use strict';
require.config({
"paths": {
"jquery": "libs/jquery-1.11.0.min",
"twitter_bootstrap": "../bower_components/bootstrap/dist/js/bootstrap.min",
"respondjs": "../bower_components/respond/dest/respond.min",
"debouncejs": "libs/dw-debounce",
"carousel": "libs/jquery.carouFredSel-6.2.1-packed",
"swipe": "libs/jquery.touchSwipe.min",
"app": "app",
"OOo_config": 'libs/oo_conf_entry-ck', // Opinion Lab pop-up
//modules
"addthis": "//s7.addthis.com/js/300/addthis_widget",
"mod_addThis": "modules/mod_AddThis",
"limelight": "//assets.delvenetworks.com/player/embed",
"mod_limelight": "modules/mod_limeLight"
},
"shim": {
"twitter_bootstrap": ["jquery"],
"carousel": ["jquery"],
"swipe": ["jquery"],
"packeryjs": ["jquery"]
}
});
require([
"jquery",
"app",
"OOo_config",
"respondjs",
"mod_addThis",
"mod_limelight"
], function ($, app) {
app.init();
});
示例模块开始如下:
define([
"jquery", "debouncejs", "limelight"
],
function ($) {
'use strict';
var playerElement = ...
});
然后运行:
node r.js -o build.js
我错过了什么?为什么它试图获取包含在那个大 js 文件中的文件?
谢谢,斯科特