问题
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