grunt-minimal-config
Grunt plugin loading splitted Gruntfiles for more readability. Useful if your Gruntfile.js is bloated by many plugins.
New simpler version !
See tag v0.5.4 for older implementation.
About
This plugin is used in solid web-base, a grunt boilerplate for solid web applications.
Installation
npm i grunt-minimal-config --save-dev
Usage
If you want to split your config file like so :
Gruntfile.js
-> Default Gruntfile, nothing changesGruntfile-scripts.js
-> all scripts tasks configurationGruntfile-styles.js
-> all styles tasks configuration
Use this Gruntfile.js
:
module{ grunt; grunt;};
src
is a glob path, it can target folder like so : grunt-configs/*.js
.
But we advice to use Gruntfile-*.js
for more readability in your file system.
Important : grunt.loadNpmTasks
needs to be after minimalConfig
configuration.
Sub-config file
Here is a sub-config file example, simple :
module{ // ------------------------------------------------------------------------- UGLIFY grunt; grunt; // ....};
Shared parameters
The __
contains all shared options. Useful if you want to share some path or parameters between sub-config files.
Why not using the default grunt template system ?
Because with this we have a better error checking, some IDE can auto-complete and also __.src + 'Main.js'
is more readable than <%= parameters.src %>Main.js
with syntax coloration.
More complete Gruntfile.js
with shared parameters between sub-configs :
module{ // ------------------------------------------------------------------------- CONFIG // Shared parameters let __ = /** * Get --optimized CLI option. * If this option is added, bundles will be compressed. */ optimizedTarget : grunt || false // Glob extension to target all JS files allJsFiles : '**/*.js' // Glob extension to target all Less files allLessFiles : '**/*.less' // Assets output assetsDestination : 'www/assets/' // Node module path nodeModulesPath : 'node_modules/' // Project source files srcPath : 'src/' ; // Load and init minimal-config grunt; grunt; // ------------------------------------------------------------------------- TASKS grunt; // We can use shared parameters here too grunt; grunt;};
Shared parameters are as second argument inside sub-config files.
We advice using __
everywhere for simplicity and auto-completion with good IDEs :
module{ if __optimizedTarget // ... // Configure less tasks grunt; grunt;};