我已经使用require.js构建了一个web应用程序,并成功地使用r.js将所有模块定义合并到一个文件中。
一旦创建了r.js优化文件,我希望只需要优化文件本身,但在加载和定义模块后,它无法执行任何代码:
require([
'app1/optimizedAppFile'
], function (optimizedApp) {
//optimizedApp is undefined, even though it loaded
//the file and executed the module definitions in debugger
});通过在require.config.js中定义优化文件的顶级模块的路径,然后在main.js中要求该路径,是否适合加载/实例化应用程序?即
requirejs.config({
paths: {
'optimizedApp.topLevelModule' : 'app1/optimizedAppFile'
//optimizedApp.topLevelModule is the full module name
//app1/optimizedAppFile is the combined file from r.js
}
});发布于 2014-04-24 15:06:40
是的,在通过rjs优化你的代码之后,你可以只需要这个文件。
然而,我今天也遇到了这个问题。经过几个小时的调试,我发现当前的1.1.2主干版本有一段代码来检测AMD (函数"define“是否存在)。
删除它后,backbone如下所示
// Backbone.js 1.1.2
// (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
(function(root, factory) {
root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
}(this, function(root, Backbone, _, $) {所以基本上我所做的就是使其全局可访问,并为其添加填充程序
require.config({
baseUrl: "/static/src/scripts/js",
paths: {
jquery: 'vendors/jquery/jquery',
underscore: 'vendors/underscore/underscore',
backbone: 'vendors/backbone/backbone',
marionette: 'vendors/backbone/backbone.marionette'
},
shim: {
jquery: {
exports: "jQuery"
},
underscore: {
exports: "_"
},
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
marionette: {
deps: ['backbone'],
exports: 'Marionette'
}
}
});检查元素并检查您的控制台,看看它报告了什么,并通过将rjs的optimize选项设置为false来切换到optimize,并查找它错误的部分。
https://stackoverflow.com/questions/23248478
复制相似问题