简体   繁体   English

Require.js + Backbone优化

[英]Require.js + Backbone optimization

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 : 我正在尝试使用r.js优化基于Require.js和Backbone的源代码,但是我在编译期间遇到以下错误:

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. 我的template_manager模块不会尝试访问任何'normalize'属性,所以我真的不明白这是什么意思。 Here's the entry point to my application as well as the require.js configuration. 这是我的应用程序的入口点以及require.js配置。

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 我的app.build.js文件如下

({
    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. 谢谢您的帮助。

James Burke says: 詹姆斯伯克说:

The text plugin needs be loaded by the loader for it to process text! 文本插件需要由加载器加载才能处理文本! depenencies. depenencies。 Loader plugins are executed as part of a build to resolve their resources. Loader插件作为构建的一部分执行以解析其资源。

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. 所以它应该足以从路径配置中删除文本:“empty:”,并且只留下exlude:in,因此它不包含在最终的构建结果中。 This assumes you have text.js available locally to be read by the optimizer. 这假设您在本地可以使用text.js以供优化器读取。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM