1

下午好,

我正在尝试使用 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

我的 template_manager 模块不会尝试访问任何“规范化”属性,所以我真的不明白这应该是什么意思。这是我的应用程序的入口点以及 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();
});

应用程序本身或多或少遵循本教程中的内容。我的 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'
    }
})

感谢您的帮助。

4

1 回答 1

4

詹姆斯伯克 说:

文本插件需要由加载器加载才能处理文本!依赖性。加载器插件作为构建的一部分执行以解析其资源。

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

于 2012-08-10T20:06:32.630 回答