【问题标题】:requireJS module.config() is missing after optimisation优化后缺少requireJS module.config()
【发布时间】:2014-07-08 14:08:39
【问题描述】:

运行 RequireJS 优化器时遇到问题...我在主配置文件中定义了以下内容:

require.config({

  config: {
    bootstrap: {
      autoload: true
    }
  },

  ... 
}

然后在我的bootstrap.js 文件中执行:

define(['module', 'app'], function (module, App) {
  'use strict';

  console.log(module.config().autoload);

  ...
});

但是autoloadundefined :( 但是,变量在非优化版本中可用。

我已经尝试过使用其他模块和其他变量,但基本上没有模块配置被推送到 Require 的优化器的输出文件中。

这是预期的行为吗?

【问题讨论】:

  • 您确定 bootstrap.js 模块在构建后具有bootstrap 名称吗?也许它有一些其他的 id,比如<libFolder>/bootstrap

标签: requirejs requirejs-optimizer


【解决方案1】:

我知道这有点晚了,但是我花了将近半天的时间来解决同样的问题,终于发现这行得通:

显然 config.js 文件或主配置是编译时配置,不会成为运行/构建配置的一部分。所以解决方案是使用 requirejs.config({}); 将模块配置添加到 main.js 文件的顶部; (这是因为它在编译和缩小/丑化之前已经使用 config)。

例如:

在 main.js 顶部添加:

requirejs.config({
  config: {
    bootstrap: {
      autoload: true
    }
  }
};)

【讨论】:

    猜你喜欢
    • 2013-11-29
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    相关资源
    最近更新 更多