【问题标题】:safely concatenating vendor javascript files using grunt - use strict使用 grunt 安全地连接供应商 javascript 文件 - 使用严格
【发布时间】:2016-04-14 08:19:36
【问题描述】:

为了加快我的 Web 应用程序加载时间,我希望连接我所有的供应商(第 3 方包)javascript 文件。例如,jQuery、Angular 和许多 bower 包。

有些包的范围是“use strict”,有些则不是。我担心连接:据我了解,如果我使用的包写得不太好,而其他一些包强制全局“使用严格”,这可能会导致错误。

是否存在将它们捆绑在一起的安全方法?

谢谢。

【问题讨论】:

  • 我也在连接 bower 和 3rd vendor 包,但我使用 gulp,我认为更好。

标签: javascript gruntjs bundling-and-minification grunt-contrib-concat


【解决方案1】:

我建议你使用 grunt 插件:grunt-contrib-concat

https://github.com/gruntjs/grunt-contrib-concat

grunt-contrib-concat 的配置在 concat 键下的配置对象中,如下所示:

concat: {
  options: {
    // define a string to put between each file in the concatenated output
    separator: ';'
  },
  dist: {
    // the files to concatenate
    src: ['src/**/*.js'],
    // the location of the resulting JS file
    dest: 'dist/<%= pkg.name %>.js'
  }
}

这里告诉 concat 任务连接所有存在于 src/ 中并以 .js 结尾的文件。

希望对你有帮助。

【讨论】:

  • 谢谢。虽然这个答案是信息性的,但它并没有解决有关串联安全的问题。
猜你喜欢
  • 2013-04-28
  • 1970-01-01
  • 1970-01-01
  • 2016-04-21
  • 1970-01-01
  • 2013-08-17
  • 2014-10-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多