我的 requirejs 优化器有点麻烦。运行优化器后,我在构建/编译文件中收到一些错误消息。在没有优化步骤的情况下运行我的 Web 应用程序时,我没有任何错误。
这是我的 client.js 文件(包含配置)(coffeescript)
requirejs.config
baseUrl: '/source/'
paths:
text: 'lib/text'
io: 'lib/socket.io'
underscore: 'lib/underscore'
backbone: 'lib/backbone'
jquery: 'lib/jquery'
# almond: 'lib/almond'
bootstrap: 'lib/bootstrap'
bootstrapFileUpload: 'lib/bootstrap-fileupload'
jqueryUniform: 'lib/jquery.uniform'
jqueryBrowser: 'lib/jquery.browser'
datatables: 'lib/jquery.dataTables'
datatables_bootstrap: 'lib/DT_bootstrap'
shim:
io:
exports: 'io'
jquery:
exports: 'jQuery'
jqueryBrowser:
deps: ['jquery']
jqueryUniform:
deps: ['jqueryBrowser', 'jquery']
underscore:
exports: '_'
backbone:
deps: ['underscore', 'jquery']
exports: 'Backbone'
datatables_bootstrap:
deps: ['jquery', 'datatables']
datatables:
deps: ['jquery']
require ['routers/router', 'backbone'], (Router, Backbone) ->
MainRouter = new Router()
Backbone.history.start()
这是我的优化器配置。在需要 'requirejs' 作为模块后,我从 nodejs 运行优化器。
config =
baseUrl: __dirname + '/../client/source'
name: 'lib/almond'
include: './client'
optimize: 'none'
out: __dirname + '/../client/' + hash + '.js'
paths:
text: 'lib/text'
io: 'lib/socket.io'
underscore: 'lib/underscore'
backbone: 'lib/backbone'
jquery: 'lib/jquery'
bootstrap: 'lib/bootstrap'
bootstrapFileUpload: 'lib/bootstrap-fileupload'
jqueryUniform: 'lib/jquery.uniform'
jqueryBrowser: 'lib/jquery.browser'
datatables: 'lib/jquery.dataTables'
datatables_bootstrap: 'lib/DT_bootstrap'
shim:
bootstrap:
exports: 'bootstrap'
bootstrapFileUpload:
exports: 'bootstrapUpload'
io:
exports: 'io'
jquery:
exports: 'jQuery'
jqueryBrowser:
deps: ['jquery']
jqueryUniform:
deps: ['jqueryBrowser', 'jquery']
underscore:
exports: '_'
backbone:
deps: ['underscore', 'jquery']
exports: 'Backbone'
datatables:
deps: ['jquery']
datatables_bootstrap:
deps: ['jquery', 'datatables']
requirejs.optimize config, (buildResponse) ->
js = true
if js && css
require './server'
, (err) ->
console.log 'requirejs err'
console.log err
我在 chrome 中看到的具体错误是:“Uncaught TypeError: Cannot read property 'defaults' of undefined”
这与此片段相关:
/* Set the defaults for DataTables initialisation */
$.extend( true, $.fn.dataTable.defaults, {
知道可能出了什么问题吗?谢谢!