我如何使用require来优化' backbone.bootstrap-modal'进入大型应用

时间:2017-05-15 05:06:12

标签: javascript twitter-bootstrap backbone.js requirejs r.js

我正在尝试优化应用程序,但每次执行此操作时,模块backbone.bootstrap-modal都会抛出错误Can't find variable: Backboner.js已成功将所有内容优化到一个文件中(因为您将看到我关闭了uglify,以便我可以看到问题所在)并且我相信Backbone已正确添加。当然其他模块正在发现jQuery没有问题。该应用程序已提供,但在启动时会抛出错误。

我使用的grunt文件包含以下requirejs任务:

requirejs: {
    buildApp: {
        options: {
            appDir:     '<%= buildPath %>/<%= appPath %>',
            baseUrl:    'js',
            dir:        '<%= distPath %>/<%= appPath %>/',
            mainConfigFile: 'public/js/myApp.js',
            paths:      {require: 'bower_components/requirejs/require'},                    
            modules:    [{
                        name:           'myApp',
                        include:        ['require'],
                        }],
            optimize:   'none',//'uglify2',
            optimizeCss:    'standard',
            preserveLicenseComments: false,
            inlineText:     true,
            removeCombined: true                
            }
        }
    },

myApp.js文件具有以下for的配置:

require.config({

    paths: {
        lodash:     'bower_components/lodash/dist/lodash',
        jquery:     'bower_components/jquery/dist/jquery',
        bootstrap:  'bower_components/bootstrap/dist/js/bootstrap',
        moment:     'bower_components/moment/moment',
        backbone:   'bower_components/backbone/backbone',
        react:      'bower_components/react/react-with-addons',
        reactDom:   'bower_components/react/react-dom',
        reactBootstrap: 'bower_components/react-bootstrap/react-bootstrap',
        babel:       'bower_components/requirejs-react-jsx/babel-5.8.34.min',
        jsx:         'bower_components/requirejs-react-jsx/jsx',
        text:        'bower_components/requirejs-text/text',
        modal:       'bower_components/backbone.bootstrap-modal/src/backbone.bootstrap-modal',
        validator:   'bower_components/bootstrap-validator/dist/validator',
        Waypoint:    'bower_components/waypoints/lib/jquery.waypoints',
        ie10workaround: 'bower_components/ie10-viewport-bug-workaround/dist/ie10-viewport-bug-workaround',
        fontawesome: 'bower_components/font-awesome/fonts',

        models:      'models',
        views:       'views',

        myView:      'myView'
        },

map: {'*': {'underscore': 'lodash'}},

shim: {
    backbone: {
              deps:     ['underscore', 'jquery'],
              exports:  'Backbone'
              },
    react:    {exports: 'React'},
    reactBootstrap: {deps: ['react']},
    bootstrap: {
               deps:    ['jquery'],
               exports: 'bootstrap'
               },
    validator: {deps:   ['bootstrap']},
    Waypoint:  {deps:   ['jquery']},
    modal:     {
               deps:    ['backbone', 'bootstrap'],
               exports: 'Backbone.BootstrapModal'
               },
    jsx:       {deps:   ['babel', 'text']},
    fonts:     {deps:   ['fontawesome']},
    ie10workaround: {
                    deps:    ['bootstrap'],
                    exports: 'ie10workaround'
                    },
    myInit:   {
              deps: ['backbone', 'react', 'reactDom', 'jsx',
                    'bootstrap', 'modal', 'validator',
                    'Waypoint', 'ie10workaround']
              }
    },

config: {
    babel:  {
            sourceMaps:     "inline",
            fileExtension:  ".jsx"
            }
    }

});

require(['./myInit'], function(myInit) {
    myInit.initialize();
    });

在这一点上我理解了这一行:

modal: {
       deps:    ['backbone', 'bootstrap'],
       exports: 'Backbone.BootstrapModal'
       },

确保为此模块加载依赖项,但是此模块报告(在运行时)它无法找到Backbone,我只是不知道为什么?

附录

这是我使用的bower.json

{
  "name": "my-web-client",
  "authors": [
    "(me <me@example.com>)"
  ],
  "description": "Web client",
  "private": true,
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "jquery": "^3.1.1",
    "lodash": "^4.17.4",
    "backbone": "^1.3.3",
    "bootstrap": "^3.3.6",
    "font-awesome": "^4.5.0",
    "react": "^15.4.2",
    "babel": "^5.8.38",
    "requirejs": "^2.3.3",
    "requirejs-react-jsx": "^1.0.2",
    "fuelux": "^3.15.11",
    "waypoints": "^4.0.1",
    "react-bootstrap": "^0.30.8",
    "backbone.bootstrap-modal": "^0.9.0",
    "bootstrap-datepicker": "^1.6.4",
    "bootstrap3-typeahead": "^4.0.2",
    "ie10-viewport-bug-workaround": "^1.0.3",
    "text": "^2.0.15",
    "bootstrap-validator": "^0.11.9"
  },
  "resolutions": {
    "backbone": "^1.3.3",
    "bootstrap": "^3.3.6"
  }
}

0 个答案:

没有答案