当使用Usemin时,如何在Concat选项中添加分隔符

9
我将使用 Grunt-usemin。但是JS拼接后的代码没有正确地以“;”分隔。如何告诉 usemin 只为 JS 文件添加分隔符,而不是 CSS 文件?
目前,我的 usemin 任务如下所示:
    useminPrepare: {
        options: {
            dest: '<%= config.dist %>'
        },
        html: '<%= config.app %>/index.html'
    },

    // Performs rewrites based on rev and the useminPrepare configuration
    usemin: {
        options: {
            assetsDirs: ['<%= config.dist %>', '<%= config.dist %>/images']
        },
        concat: {
            separator: ';'
        },
        html: ['<%= config.dist %>/{,*/}*.html'],
        css: ['<%= config.dist %>/styles/{,*/}*.css']
    },

另一个用例是将每个连接的模块包装在IIFE中,这需要进行配置,但只应用于*.js文件:
concat: {
    options: {
        banner: ';(function () {',
        separator: '})(); (function () {',
        footer: '})();'
    }
}
1个回答

4
 concat: {
  options: {
    process: function (src, filepath) {
      if (filepath.split(/\./).pop() === 'js') {
        return src + ';\n';
      }
      return src;
    }
  }
}

流程选项的解释链接

该函数将文件路径用 .(点)作为分隔符拆分成一个数组。数组中的pop()方法返回数组的最后一项,这应该是文件扩展名。


你能解释一下这里正在发生什么并添加到相关文档的链接吗? - Pier-Luc Gendreau

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接