【问题标题】:How do I prevent requirejs from including all the source files and only include the module files?如何防止 requirejs 包含所有源文件而只包含模块文件?
【发布时间】:2014-11-18 13:19:38
【问题描述】:

当我使用 r.js 构建项目时(我是通过 grunt 进行的,但我离题了),它会 uglify 并压缩项目的所有 javascript 文件并将它们包含在 build 文件夹中,即使所有这些文件已被压缩为单个 javascript 文件,不再以单独的形式使用。

我正在使用模块,所以我不能使用“out”标志 b/c 它不兼容。我正在使用 grunt-contrib-clean 来清理所有额外的文件,但如果我可以避免一开始就包括它们,那将是理想的。

这是我咕哝的 options.js:

module.exports = {
  appDir: 'src',
  baseUrl: 'js/',
  mainConfigFile: 'src/js/common.js',
  dir: 'www',
  modules: [
    {
      name: 'common',
      include: [
          'jquery',
          'underscore',
          'handlebars',
          'hbs',
          'i18nprecompile',
          'json2',
          'Class'
      ]
    },
    {
        name: 'app/page1',
        exclude: ['common']
    },
    {
        name: 'app/page2',
        exclude: ['common']
    }
  ]
};

当它构建时,它包括 lib 文件夹中的所有文件(当唯一需要的是 require.js 时),它包括由 page1 和 page2 导入的所有 javascript 文件的丑化版本,即使所有这些文件已经合并为 page1.js 和 page2.js。

是我遗漏了什么还是构建后清理只是生活中的一个事实?

【问题讨论】:

    标签: requirejs gruntjs


    【解决方案1】:

    可以通过将removeCombined设置为false来简单修复:

        //If set to true, any files that were combined into a build layer will be
        //removed from the output folder.
        removeCombined: false,
    

    任何其他构建选项的详细信息can be found in this example file

    【讨论】:

      【解决方案2】:

      为此,您可以使用:

      skipDirOptimize: true, 
      removeCombined: true
      

      skipDirOptimize: true会阻止requirejs优化其他文件

      removeCombined: true 将删除所有组合到模块文件中

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-17
        • 1970-01-01
        • 2011-04-14
        • 2019-01-21
        • 2012-06-08
        • 1970-01-01
        • 2021-04-24
        • 1970-01-01
        相关资源
        最近更新 更多