小编Pat*_*ick的帖子

grunt.js中目标的动态映射

我有一个包含几个子文件夹的项目,其中包含我要连接的JavaScript文件.什么是正确的配置方式?

例如.

来源:/modules/$modulename/js/*.js(几个文件)dest:/modules/$modulename/js/compiled.js

所以我想要做的是将每个子文件夹的未知/未配置的子文件夹($ modulename)的js文件编译成一个文件.

这可能吗?


以下函数(在hereandnow78的指令之后构建)完成了这项工作:

grunt.registerTask('preparemodulejs', 'iterates over all module directories and compiles modules js files', function() {

    // read all subdirectories from your modules folder
    grunt.file.expand('./modules/*').forEach(function(dir){

        // get the current concat config
        var concat = grunt.config.get('concat') || {};

        // set the config for this modulename-directory
        concat[dir] = {
            src: [dir + '/js/*.js', '!' + dir + '/js/compiled.js'],
            dest: dir + '/js/compiled.js'
        };

        // save the new concat config
        grunt.config.set('concat', concat);

    });

});
Run Code Online (Sandbox Code Playgroud)

之后我将preparemodulejs放在我的默认配置中的concat作业之前.

gruntjs

17
推荐指数
1
解决办法
8863
查看次数

如何在 webpack 配置中保存 contenthash

我之前将 webpack 的 [hash] 值保存到了一个 meta.json 文件中:

class MetaInfoPlugin {
  constructor(options) {
    this.options = { filename: 'meta.json', ...options };
  }

  apply(compiler) {
    compiler.hooks.done.tap(this.constructor.name, (stats) => {
      const metaInfo = {
        // add any other information if necessary
        hash: stats.hash
      };
      const json = JSON.stringify(metaInfo);
      return new Promise((resolve, reject) => {
        fs.writeFile(this.options.filename, json, 'utf8', (error) => {
          if (error) {
            reject(error);
            return;
          }
          resolve();
        });
      });
    });
  }
}

module.exports = {
  mode: 'production',
  target: 'web',
...
  plugins: [
    new MetaInfoPlugin({ …
Run Code Online (Sandbox Code Playgroud)

webpack webpack-5

8
推荐指数
1
解决办法
6394
查看次数

标签 统计

gruntjs ×1

webpack ×1

webpack-5 ×1