Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split up Gruntfile

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?

like image 544
rphilipsenbas Avatar asked Dec 08 '14 11:12

rphilipsenbas


People also ask

What is the use of Gruntfile?

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node.

Is grunt deprecated?

grunt. util. _ is deprecated and we highly encourage you to npm install lodash and var _ = require('lodash') to use lodash .

What is grunt js file?

json file, which is then parsed to a JavaScript object. Grunt has a simple template engine to output the values of properties in the configuration object. Here we tell the concat task to concatenate all files that exist within src/ and end in .

Where is Gruntfile JS?

The Gruntfile. js or Gruntfile. coffee file is a valid JavaScript or CoffeeScript file that belongs in the root directory of your project, next to the package.


1 Answers

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
};
like image 133
hereandnow78 Avatar answered Oct 21 '22 23:10

hereandnow78