gruntjs load external config

廉价感情. 提交于 2019-12-10 18:13:38

问题


Ahoy grunt-masters!

I would like to load external config files into grunt so that I can do something like this:

$ grunt dev:homepage

and it would load in homepage-config.json, then run watch

$ grunt dev:contact

and it would load in contact-config.json, then run watch

Each config file would provide a particular setup 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

});

Within that dev task the externally loaded config works just fine. That console.log would return what you'd expect, and the watch task kicks off with the externally specified setup.

My problem is that once that watch starts triggering tasks, those tasks no longer seem to have access to this externally loaded config. Somewhere between the dev task and the tasks triggered by watch, the dynamically loaded config gets blown away.

Can anyone shed light on why this is happening and how I might accomplish my goal?

Many thanks, -James


回答1:


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



来源:https://stackoverflow.com/questions/14359473/gruntjs-load-external-config

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!