Grunt需要优化 - 未定义Backbone

时间:2014-09-23 10:07:04

标签: backbone.js requirejs gruntjs marionette

我已经构建了一个Marionette / Requirejs应用程序,我正在尝试优化它。在浏览器中编译和测试后,我收到错误“Backbone is not defined”。

修改

我读到从require项目中生成mainConfigFile = my main.js文件解决了这些类型的问题,但是当我尝试添加并从gruntfile中删除所有路径信息时,我得到了一个grunt编译错误,我的主要。 js文件不是有效的JSON。

结束修改

继承人我的gruntfile.js requirejs config:

requirejs: {
      compile: {
        options: {
            baseUrl: "scripts",
            paths: {
                requireLib: 'lib/require',
                templates: '../templates',
                underscore: 'lib/underscore',
                backbone: 'lib/backbone',
                jquery: 'lib/jquery',
                backbonevalidation: 'lib/backbone-validation',
                marionette: 'lib/backbone.marionette',
                json2: 'lib/json2',
                text: 'lib/text',
                errorlogger: 'lib/errorlogger',
                moment: 'lib/moment.min',
                glossary: 'lib/glossary',
                facebook: '//connect.facebook.net/en_US/all',
                "codebird": 'lib/codebird',
                "cryptojs": 'lib/md5',
                jquerySteps: 'lib/jquery.steps',
                JQValidate: 'lib/jquery.validate.min',
                numeral: 'lib/numeral',
                async: 'lib/async',
                homeloanAmort: 'lib/homeloanamortisation',
                financial: 'lib/financial',
                bonds: 'lib/finance/bonds',
                common: 'lib/finance/common',
                daycountbasis: 'lib/finance/daycountbasis',
                depreciation: 'lib/finance/depreciation',
                irr: 'lib/finance/irr',
                loan: 'lib/finance/loan',
                misc: 'lib/finance/misc',
                oddbonds: 'lib/finance/oddbonds',
                tbill: 'lib/finance/tbill',
                tvm: 'lib/finance/tvm',
                retirementneeds: 'lib/retirementneeds',
                numeral: 'lib/numeral',
                carloanamortisation: 'lib/carloanamortisation',
                carleasebuy: 'lib/carleasevsbuy',
                cookie: 'lib/jquery.cookie',
                homerentvsbuy: 'lib/homerentvsbuy',
                "JQstorageapi": 'lib/jquery.storageapi.min',
                regiontransitions: 'lib/region-transitions'
            },

            shim : {
                underscore: {
                    exports: '_'
                },
                backbone: {
                    deps: ['underscore', 'jquery'],
                    exports: 'Backbone'
                },
                backbonevalidation: {
                    deps: ['backbone'],
                    exports: 'Backbone'
                },
                marionette: {
                    deps: ['jquery', 'underscore', 'backbone'],
                    exports: 'Marionette'
                },
                errorlogger: {
                    deps: ['jquery']
                },
                numeral: {
                    exports: "numeral"
                },
                jquerySteps: {
                    deps: ["jquery"],
                    exports: "Steps"
                },
                JQValidate: {
                    deps: ["jquery"],
                    exports: "JQValidate"
                },
                JQstorageapi: {
                    deps: ["jquery"],
                    exports: "JQstorageapi"
                },
                facebook: {
                    exports: 'FB'
                },
                cryptojs: {
                    exports: 'CryptoJS'
                },
                financial: {
                    deps: ['bonds','common','daycountbasis','depreciation','irr','loan','misc','oddbonds','tbill','tvm'],
                    exports :'financial'
                }
            },

            baseUrl : "scripts",
            name: "main",
            out: "optimised/js/main.min.js",
            removeCombined: true,
            include: ["requireLib", 'main.js'],
            out: "optimised/js/main.min.js",
            findNestedDependencies: true
        }
      }
    },

我在某个地方出错了,经过一些搜索,我知道它与Shim,路径和使用AMD模块有关。任何方向都会非常感激。

1 个答案:

答案 0 :(得分:0)

在这里找到答案:http://jrburke.com/2014/02/16/requirejs-2.1.11-released/

<强>解决方案

wrapShim: true,添加到gruntfile中需要配置解决它。