Here is an potential example of your structure :
main-folder
├── package.json
├── Gruntfile.js
├── grunt
│ ├── config.js
│ ├── config
│ │ │ ├── copy.js
│ │ │ ├── sass.js
│ │ │ ├── sync.js
│ │ │ ├── linkAsset.js
│ │ │ └── uglify.js
│ ├── register
│ │ │ ├── compileAssets.js
│ │ │ ├── linkAssets.js
│ │ │ ├── build.js
│ │ │ └── buildProd.js
├── project-1
│ └── folders and files ...
├── project-2
│ └── folders and files ...
- package.json : contains all your grunt-plugins dependencies and other useful npm modules
- Gruntfile.js : load and configure all tasks in
grunt/config
and grunt/register
folder
Read this if you want to have more information to setup this configuration of grunt : How to create and organise config and register grunt tasks
Configuration file :
I recommend you also to use a configuration file (E.g : main-folder/grunt/config.js
) file to register some shortcut, variables to make your grunt tasks more dynamic.
Example :
var version = '0.1.0';
var project1Dir = 'project-1';
var project2Dir = 'project-2';
module.exports.version = version;
module.exports.project1Dir = project1Dir;
module.exports.project2Dir = project2Dir;
And import this config in each task with : var config = require('../config');
. It will be easy to refactor the code if you rename for example the folder project1
.
Run tasks :
Now when you are working in your directory (main-folder/project1
or main-folder/project2
) and entering your grunt command, use b
flag to tell to grunt where is your Gruntfile.js
file.
Example :
grunt -b ../ build
You can also configure in the code this behavior. Read Grunt documentation for more information : Grunt CLI - b flag