【发布时间】:2011-10-02 08:12:04
【问题描述】:
好吧,他就是那个东西。我正在为我的 AMD 加载程序使用 curl.js,但我不太喜欢“cram”,因为它需要在 unix 上运行并且我正在 Windows 上开发。所以想到了 RequireJS 库中 nodeJS 的 r.js 适配器,因为 node 已经有 Windows 的二进制文件。
现在当前版本 (1.6.4) 中的 jQuery 不是有效的 AMD 模块(版本 1.7 中)并且 jQueryUI 组件中存在依赖关系,所以我不得不像这样伪造:
curl( [js!Core/jquery.js] )
.then( function() {
define('jquery', function() { return jQuery; });
})
我的应用程序对此很满意。但是在这部分使用 r.js(版本 0.26.0)失败并出现以下错误:
Tracing dependencies for: boot
function (){return jQuery}
node.js:207
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: jQuery is not defined
at eval at <anonymous> (r.js:7468:30)
at main (r.js:770:33)
at callDefMain (r.js:840:18)
这是我的 app.build.js
({
appDir: '../',
baseUrl: 'Scripts/',
paths: {
'link': '../../../Lib/@Javascript Libs/curl.js/src/curl/plugin/link.js'
},
dir: 'built',
optimize: 'none',
modules: [
{ name: 'boot' }
]
})
这里是完整的 boot.js 供参考(coffeescript):
require([
'link!styles/main.css'
'js!Core/jquery.js!order'
'js!Core/underscore.js!order'
'js!Core/backbone.js!order'
]).then ->
define 'jquery', -> jQuery
.next(['Router/MainRouter'])
.then (MainRouter) ->
new MainRouter()
Backbone.history.navigate('home') unless Backbone.history.start(
pushState: false
)
提前感谢您提供任何可以捕获的提示...
【问题讨论】:
-
哦,我想知道那里发生了什么。 RequireJS 不适用于基于承诺的 AMD 加载,因此它不理解那些“then”和“next”函数,并试图在 jquery 真正加载之前定义它......我能对此做些什么吗?
标签: optimization node.js requirejs js-amd