grunt.js - 将 JavaScript 连接到函数调用中

grunt.js - concat javascripts into function call

本文关键字:函数调用 连接 JavaScript js grunt      更新时间:2023-09-26

我想将许多Javascript文件连接到函数调用中。

结果我想得到这样的东西:

(function() {
  // contents of file 1
  // contents of file 2
  // contents of file ..
})()

在grunt-contrib-concat包中没有这样的选择。我也没有找到任何包裹。

知道怎么做吗?

你可以用grunt-contrib-concat解决这个问题。使用横幅和页脚选项,如下所示:

 concat: {
    options: {
        banner: '(function() {'n',
        footer: ''n})()'
    },
    dist: {
       src: ['file1.js', 'file2.js'],
       dest: ''
    }
}