【问题标题】:RequireJS bundles config vs bundling with modulesRequireJS 捆绑配置与捆绑模块
【发布时间】:2017-04-15 10:48:45
【问题描述】:
  1. requirejs bundles config 和 使用模块(即多个模块)进行优化?在我看来 两者都产生相同的东西——而不是创造一个 单个优化文件,创建多个优化文件,其中每个 具有多个模块的文件。我的理解正确吗?与模块捆绑相比,使用捆绑包有什么优势吗?

  2. 当使用 r.js 'modules' 进行优化时,可以提供一个 'create: true' 配置,如果模块名称创建一个文件 不是现有模块。但是我没有看到其他模块 使用 'create: true' 引用模块相应更改。

    "modules": [{ "name": "some/existing/Module" }, { "name": "some/non/existing/path", "create": true, "include": ["x", "y"] }]

    上述情况下JS文件"some/non/existing/path.js" 由加载到浏览器中的 r.js 生成?

【问题讨论】:

    标签: javascript requirejs bundling-and-minification requirejs-optimizer


    【解决方案1】:
    1. 将所有模块捆绑在一个文件中可能并不适合所有应用程序。由于 require JS 是一个按需 JS 模块加载器,因此某些模块可能一直都不需要。根据使用模式将捆绑包拆分为单独的捆绑包可以提高应用程序的加载效率。

    2. 在这种情况下,它会生成一个包含模块“x”、“y”和“some/non/existing/path”的文件(因为您没有提到 skipModuleInsertiontrue) 在路径“some/non/existing/path”中,如

    define('x', [dependencies], function(){})
    
    define('y', [dependencies], function(){})
    
    define('some/non/existing/path', [dependencies], function(){})

    这将从 requirejs 配置文件中加载。如果您在 bundlesConfigOutFile 路径中提供文件路径,则 Require js 会将这些配置插入到配置文件中。有关更多信息,请参阅此 sample configuration file.

    【讨论】:

      猜你喜欢
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 2014-09-30
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-17
      相关资源
      最近更新 更多