我正努力让{j}在optimizing之后使用r.js
它可以很好地预先优化
我正在关注使用empty:
配置main.js和构建配置文件的文档
但是,优化后,不再加载CDN脚本。
公开/ index.html中
<script data-main="editor/js/main" src="editor/js/vendor/require.js"></script>
公开/编辑/ JS / main.js
requirejs.config({
baseUrl: "/editor/js",
paths: {
"jquery": "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min",
"order": "vendor/require_order",
"underscore": "vendor/underscore",
"handlebars": "vendor/handlebars-1.0.0.beta.4",
"jquery.mobile.router": "vendor/jquery.mobile.router",
"jquery.mobile": "http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min"
}
});
require(["order!jquery", "order!underscore", "order!handlebars", "order!jam", "order!jquery.mobile"], function () {
//loaded
});
配置/ build.js
({
baseUrl: "../public/editor/js",
name: "main",
out: "../public/editor/js/main-built.js",
paths: {
"order": "vendor/require_order",
"underscore": "vendor/underscore",
"handlebars": "vendor/handlebars-1.0.0.beta.4",
"jquery.mobile.router": "vendor/jquery.mobile.router",
"jquery": "empty:",
"jquery.mobile": "empty:"
}
})
当我运行r.js node config/r.js -o config/build.js
时
main-built.js已成功构建。
答案 0 :(得分:0)
您是否有使用订单插件加载所有内容的特殊原因?
您的内置JavaScript中是否存在加载顺序问题?
如果你正常加载jQuery mobile(没有插件),你的“空”配置应该会生效。
require(["jquery", "underscore", "handlebars", "jam", "jquery.mobile"], function () {
http://requirejs.org/docs/optimization.html#empty
您还需要为jQuery.mobile.router
定义依赖关系链requirejs.config({
paths: {
"jquery": "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min",
"order": "vendor/require_order",
"underscore": "vendor/underscore",
"handlebars": "vendor/handlebars-1.0.0.beta.4",
"jquery.mobile.router": "vendor/jquery.mobile.router",
"jquery.mobile": "http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min"
},
shim: {
"router": {
"deps" : ["jquery.mobile"]
},
"jquery.mobile" : {
"deps" : [ "jquery.mobile.router"],
"exports": "$.mobile"
},
"jquery.mobile.router": {
"exports": "$.mobile.Router"
}
}
});
看到这个问题的答案:
Require.js with jQueryMobile-Router
我希望用requirejs解决你的问题,一旦你习惯了它的结构,我发现它是一个非常强大和有用的工具。
_Pez