Require.js + Backbone optimization

2019-08-12 04:47发布

问题:

Good afternoon,

I'm trying to optimize a source code based on Require.js and Backbone using r.js but I'm getting the following error during the compilation :

Tracing dependencies for: main
Cannot optimize network URL, skipping: empty:.js
TypeError: Cannot read property 'normalize' of undefined
In module tree:
    main
      app
        router
          views/main_panel/event_details
            helpers/template_manager

My template_manager module does not try to access any 'normalize' property so I don't really understand what is that supposed to mean. Here's the entry point to my application as well as the require.js configuration.

require.config({
  paths: {
order: 'libs/requirejs-plugins/order',
        text: 'libs/requirejs-plugins/text',
        jQuery: 'libs/jquery/jquery',
        Underscore: 'libs/underscore/underscore',
        Backbone: 'libs/backbone/backbone',
        templates: '../templates',
    Sync: 'helpers/sync'
  }
});

require([
  'app',
  'event_manager',
  'order!https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
  'order!libs/underscore/underscore-min',
  'order!libs/backbone/backbone-min',
  'helpers/objects_extension',
  'helpers/date_extension',
  'helpers/assets'
], function(App){
    App.initialize();
});

The application itself more or less follows what's in this tutorial. My app.build.js file is as follow

({
    appDir: "../",
    baseUrl: "js",
    dir: "../app-build",
    modules: [
        {
            name: "main"
        }
    ],
    paths: {
        order: 'empty:',
        text: 'empty:',
        jQuery: 'empty:',
        Underscore: 'empty:',
        Backbone: 'empty:',
        templates: '../templates',
        Sync: 'helpers/sync'
    }
})

Thank you for your help.

回答1:

James Burke says:

The text plugin needs be loaded by the loader for it to process text! depenencies. Loader plugins are executed as part of a build to resolve their resources.

So it should be enough to remove the text: "empty:" from the paths config, and just leave the excludes: in so it is not included in the final build result. This assumes you have text.js available locally to be read by the optimizer.

https://github.com/jrburke/r.js/issues/221