1

I am using Grunt for building javascript apps. Now I have multiple applications that work this way.

My question is: Is it possible to have one grunt instance on a certain central directory and use this for multiple projects at the same time?

For example: Can a have multiple grunt-watches for different projects running at the same time?

Would be nice to get some clarity here.

Thanks a lot!

1 Answer 1

1

You can install the Grunt main project folter "outside" your subproject folder.

-gruntJs folder
---gruntFile.js
-projectSubFolder
---project_1
-----sass
-----css
---project_2
-----sass
-----css
---project_3
-----sass
-----css

You can use dynamic parameters to pass in the task to target the single project you have:

for example:

grunt sass:<projectName>

than in the gruntFile.js you can use something like this:

sass: {
 dist: {
      files: [{
        expand: true,
        src: ['../projectSubFolder/<%= grunt.task.current.args[0] %>/sass/*.scss'],
        dest: '../projectSubFolder/<%= grunt.task.current.args[0] %>/css',
        extDot: 'last',
        ext: '.css'
      }]
 }
},

a generic task that execute it for all the project for example:

grunt.registerTask('sassAll', [ 'sass:project_1', 'sass:project_2', 'sass:project_3' ]);

it is good if you have multiple project that have the same tasks. if you need to split the taskt than you can creare multiple different tasks, setting up the directory/process for it.


you can add multiple parameters for the grunt task if you want more versatility.

watch: {
 less: {
  files: ['../projectSubFolder/<%= grunt.task.current.args[0] %>/less/*.less',
          '../projectSubFolder/<%= grunt.task.current.args[0] %>/less/**/*.less',
          '../projectSubFolder/<%= grunt.task.current.args[0] %>/js/*.js'
        ],
  tasks: [
        'less:<%= grunt.task.current.args[0] %><%= grunt.task.current.args[1] %>',
        'uglify:<%= grunt.task.current.args[0] %><%= grunt.task.current.args[1] %>'
        ]
  },
},
less: {
 project_1: {
    options: {
      cleancss: true,
      compress: true
    },
    files: {
       '../projectSubFolder/<%= grunt.task.current.args[1] %>/css/style.min.css': '../projectSubFolder/<%= grunt.task.current.args[1] %>/less/*.less'
    }
  },
},

grunt watch:<projectName>:<taskName>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.