Download external gruntjs configuration

Ahoy the master grunt!

I want to load external configuration files in grunt so that I can do something like this:

$ grunt dev:homepage

and it will be loaded in homepage-config.json , then run watch

$ grunt dev:contact

and it will be loaded in contact-config.json , then run watch

Each configuration file will provide a specific setting for tasks: watch, jshint, concat, etc.

Inside my gruntfile, I have a task called dev

 grunt.registerTask('dev', 'loads in external -config.json file, then runs watch', function(name) { grunt.initConfig(grunt.file.readJSON(name + '-config.json')); console.log(grunt.config('jshint.pageConfig.src') // correctly logs whatever had been specified in my external json file grunt.task.run('watch'); // correctly boots up watch with configuration specified by external file }); 

Inside this dev task, external configuration loading works fine. This console.log will return what you expect, and the watch task will start working with the installation installed externally.

My problem is that as soon as watch starts the task launch, these tasks no longer have access to this external downloadable config. Somewhere between the dev task and the tasks called by watch , the dynamically loaded configuration is reset.

Can anyone shed some light on why this is happening and how I can fulfill my goal?

Thanks a lot James

+3
source share
1 answer

You need to specify nospawn : true in your watch task configuration so that the tasks being called run in the same context. See this section of the documentation for more information / examples.

+3
source

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


All Articles