使用requirejs优化器优化后出错

时间:2013-09-17 12:11:25

标签: requirejs

我收到以下错误

uncaught exception: Please include Backbone.ModelBinder.js before Backbone.CollectionBinder.js

完成后

node r.js -o build.js

我的build.js文件是

({    
    "mainConfigFile": 'js/main.js',
    "name": "main", 
    "include": [
        "lib/require/require-with-comments.js"
    ], 
    "exclude": [], 
    "optimize": "uglify2", 
    "out": "main-built.js", 
    "insertRequire": [
        "js/main"
    ]
})

我的需要配置如下

require.config({
    // The shim config allows us to configure dependencies for
    // scripts that do not call define() to register a module
    urlArgs: "bust=" + (new Date()).getTime(),    
    shim: {
        'underscore': {
            exports: '_'
        },
        'bootstrap': {
            deps: [
                'jquery'
            ]
        },
        'backbone': {
            deps: [
                'underscore',
                'jquery'
            ],
            exports: 'Backbone'
        }, 'handlebars': {
            exports: 'Handlebars'
        }, 'handlebarsview': {
            deps: [
                'backbone',
                'handlebars'
            ],
            exports: 'HandlebarsView'
        }, 'highcharts': {
            deps: [
                'jquery'
            ],
            exports: 'highcharts'
        }
        , 'collectionbinderview': {
            deps: [
                'backbone',
                'jquery',
                'underscore',
                'modelbinderview'
            ]
        }, 'purl' : {
            deps : ['jquery']
        }
        , 'select2': {
            deps: [
                'jquery'
            ],
            exports: 'select2'
        }
        , 'customSelect': {
            deps: [
                'jquery'
            ],
            exports: 'customSelect'
        }
        , 'datepicker': {
            deps: [
                'jquery',
                'momentjs'
            ],
            exports: 'datepicker'
        }
    },
    paths: {
        jquery: 'lib/jquery/jquery.min',
        bootstrap: 'lib/bootstrap/bootstrap',
        underscore: 'lib/lodash/lodash.min',
        backbone: 'lib/backbone/backbone',
        text: 'lib/require/text',
        handlebars: 'lib/view/hacked-handlebars-1.0.0',
        handlebarsview: 'lib/view/backbone.handlebars',
        collectionbinderview: 'lib/view/Backbone.CollectionBinder',
        modelbinderview: 'lib/view/Backbone.ModelBinder',        
        highcharts: 'lib/charting/highcharts',
        momentjs: 'lib/view/moment',
        select2: 'lib/select2/select2',
        customSelect: 'lib/customSelect/customSelect',
        datepicker: 'lib/view/datepicker',
        purl : 'lib/purl/purl'
    }
});

有谁能告诉我我做错了什么?

2 个答案:

答案 0 :(得分:0)

collectionbinderview:'lib / view / Backbone.CollectionBinder', modelbinderview:'lib / view / Backbone.ModelBinder',

尝试切换它们。将CollectionBinder放在CollectionBinder之前。

答案 1 :(得分:0)

发生此问题是因为CollectionBinder在加载后立即执行,而ModelBinder是AMD,因此尚未定义。简而言之,CollectionBinder不是AMD库。

我从以下问题得到了上述解决方案:
https://github.com/theironcook/Backbone.ModelBinder/pull/111
承诺是 https://github.com/rweng/Backbone.ModelBinder/commit/9e93e7c9236ccef71c87a3dc4023910f9ac03803