I've installed grunt-hub into my workspace, which looks like this
hub/
node_modules/
grunt/
grunt-hub/
Gruntfile.js
package.json
In Gruntfile.js I have written this,
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
pkg : grunt.file.readJSON( 'package.json' ),
hub: {
src: [
'hub/*/Gruntfile.js'
],
watch: {
src: '<%= hub.src %>',
tasks: ['watch']
}
}
});
grunt.loadNpmTasks('grunt-hub');
grunt.registerTask('default', []);
}
I have four files within the hub directory, which have their own Gruntfiles.
hub/
project1/
...
Gruntfile.js
...
project2/
...
Gruntfile.js
...
project3/
...
Gruntfile.js
...
project4/
...
Gruntfile.js
...
When I run...
grunt hub
...it works perfectly fine; it watches all the changes I make and runs how I've commanded them to run.
The only problem is in the command prompt I am told...
>> C:\Grunt\hub\project1\Gruntfile.js:
Running "watch" task
Waiting...
>> C:\Grunt\hub\project2\Gruntfile.js:
Running "watch" task
Waiting...
>> C:\Grunt\hub\project3\Gruntfile.js:
Running "watch" task
Waiting...
...but am not told that project4 is being watched. When I make changes to files relating to project4, nothing happens, whereas it does for everything else.
What can I do to make it watch project4 as well?
尝试根据https://www.npmjs.org/package/grunt-hub更改 options.concurrent
The livereload has an effect on this. Here are some options:
Add the watch task to your tasks list in your hub task config (grunt.config.hub.js):
watch: { options: { allowSelf: true }, src: hubSettings.src, tasks: ['watch'] },
OR:
grunt hub
with the watch task set as default: grunt hub:target:watch
References
I have this working in the following way:
// scss files to watch ##
watch_scss: [
'wp-content/themes/**/*.scss', // regex to track all sass files in themes ##
'wp-content/plugins/**/*.scss', // regex to track all sass files in plugins ##
],
// grunt hub - master controller ##
hub: {
all: {
options: {
allowSelf: true,
},
src: [
'Gruntfile.js', // this grunt file ##
'wp-content/themes/**/Gruntfile.js', // in themes ##
'wp-content/plugins/**/Gruntfile.js' // in plugins ##
],
tasks: [ 'default' ]
},
},
// watch task ##
'watch': {
// track changes to scss src files ##
'sass': {
'options': {
'livereload': 1337, // dedicated port for live reload ##
'debounceDelay': 5000, // wait a little for sass to complete ##
},
'files':
'<%= watch_scss %>' // files defined in config ##
,
'tasks': [
[], // nada ##
]
},`
Be sure to include grunt-watch task:
grunt.loadNpmTasks( 'grunt-contrib-watch' ); // Watcher ##
And define a grunt task for default:
grunt.registerTask( 'default', [
'watch', // watch ##
]);
Make sure your individual gruntfiles don't also have livereload option on watch tasks, then run "grunt hub:all:watch"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.