Split up Gruntfile

拜拜、爱过 提交于 2019-12-10 13:39:44

问题


My Gruntfile is becoming pretty big right now and I want to split it up into multiple files. I've Googled and experimented a lot but I can't get it to work.

I want something like this:

Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    concat: getConcatConfiguration()
  });
}

functions.js

function getConcatConfiguration() {
  // Do some stuff to generate and return configuration
}

How can I load functions.js into my Gruntfile.js?


回答1:


How you can do it:

you need to export your concat configuration, and require it in your Gruntfile (basic node.js stuff)!

i would recommend putting all every taskspecific configuration into one file named after the configuration (in this case i named it concat.js).

Moreover i moved concat.js into a folder named grunt

Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    concat: require('grunt/concat')(grunt);
  });
};

grunt/concat.js

module.exports = function getConcatConfiguration(grunt) {
  // Do some stuff to generate and return configuration
};

How you SHOULD do it:

there was already someone there who created a module named load-grunt-config. this does exactly what you want.

go ahead and put everything (as mentioned above) into separate files into a location of your choice (default folder ist grunt).

then your standard gruntfile should probably look like this:

module.exports = function(grunt) {
  require('load-grunt-config')(grunt);

  // define some alias tasks here
};


来源:https://stackoverflow.com/questions/27356538/split-up-gruntfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!