javascript - 如何使用 load-grunt-config 将参数传递给外部文件中定义的 grunt 任务?

标签 javascript parameters gruntjs external

我的第一篇文章,请多多指教^^
我正在使用 Grunt 和 load-grunt-config 将我的任务设置拆分为多个文件,如果我使用这种设置,则效果很好:

./Gruntfile.js:

module.exports = function(grunt) {
  var path = require('path');
  var myParam = grunt.option('myParam') || 'responsive';
  // Project configuration.
  grunt.initConfig({
    ...
    require('load-grunt-config')(grunt);
    ...
  });
  ...
};

./grunt/concat.js:

var conf = require('../mytheme.config.json');
module.exports = {
  dist: {
    src: conf.theme.js.src,
    dest: conf.theme.js.dist + 'mytheme.bundle.js',
    options: {
    }
  }
};

我的问题如下:如何将“myParam”变量传递给“concat.js”文件中的外部配置?

我不明白如何使用https://github.com/creynders/load-grunt-configs中的文档来做到这一点

谢谢

最佳答案

好吧,我发现了一些对我有用的东西:

./Gruntfile.js

module.exports = function(grunt) {
  // Define 
  var myParam = grunt.option('myParam') || 'responsive';

  // Plugins
  require('time-grunt')(grunt);
  require('jit-grunt')(grunt);
  require('load-grunt-config')(grunt, {
    configPath: path.join(process.cwd(), 'grunt/config'),
    jitGrunt: {
      customTasksDir: 'grunt/tasks'
    },
    data: {
      myParam: myParam // accessible with '<%= myParam %>'
    }
  });
};

./grunt/config/concat.js

var conf = require('../../mytheme.config.json');
module.exports = {
  dist: {
    src: conf.theme.js.src,
    dest: conf.theme.js.dist + '<%= myParam %>/mytheme.bundle.js',
    options: {
    }
  }
};

希望它也能帮助别人。

关于javascript - 如何使用 load-grunt-config 将参数传递给外部文件中定义的 grunt 任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39975053/

相关文章:

javascript - 使用node.js复制文件并可以取消

c# - 列表是按值传递的吗?

python - 'cv2.face_BasicFaceRecognizer' 对象没有属性 'getParams' Python

javascript - 如何将函数的结果存储在同一个对象中?

javascript - Date.now() 无法在 Float32Array 中更新

javascript - 垂直对齐动画 div

c++ - 错误无效使用 void 表达式。试图将参数传递给函数

javascript - 从另一个 gruntfile 加载 grunt 任务

html - 咕噜服务 :dist using local file paths

javascript - 使用 Grunt Serve 在本地主机上显示网站?