Split Grunt File

My Gruntfile is getting pretty big now, and I want to split it into several files. I googled and experimented a lot, but I can't get it to work.

I need 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 .js functions into my Gruntfile.js file?

+5
source share
1 answer

How can you do this:

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

I would recommend putting the entire configuration of each task in one file with the name after the configuration (in this case, I called it concat.js ).

Also, I moved concat.js to a folder called grunt

Gruntfile.js

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

footman / concat.js

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

How you SHOULD do this:

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

go and put everything (as mentioned above) in separate files to your chosen location (default ist grunt folder).

then your standard grunt file should look something like this:

 module.exports = function(grunt) { require('load-grunt-config')(grunt); // define some alias tasks here }; 
+6
source

Source: https://habr.com/ru/post/1208569/


All Articles