当我使用grunt-contrib-watch
更改js文件时,我试图让Grunt重新加载它们。这是我的 Gruntfile
:
module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
connect: {
all: {
options:{
port: 9000,
hostname: "0.0.0.0",
base: 'app',
keepalive: true,
middleware: function(connect, options) {
return [
require('grunt-contrib-livereload/lib/utils').livereloadSnippet,
connect.static(options.base)
];
}
}
}
},
open: {
all: {
path: 'http://localhost:<%= connect.all.options.port%>'
}
},
watch: {
options: {
livereload: true
},
js: {
files: ['app/js/**/*.js'],
tasks: ['jshint'],
}
}
});
// Creates the `server` task
grunt.registerTask('server',[
'open',
'livereload-start',
'connect',
'watch'
]);
};
当我更改 js 文件时,没有任何反应。任何帮助都会很棒。
最佳答案
我之前没有尝试过在中间件中使用livereloadSnippet
,所以我不确定那里可能出了什么问题。但是,如果您只想要常规的 LiveReload 设置,则可以使用 grunt-contrib-connect
插件提供的 livereload
选项:
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
connect: {
all: {
options:{
port: 9000,
hostname: '0.0.0.0',
base: 'app',
keepalive: true,
livereload: true,
open: true
}
}
},
watch: {
options: {
livereload: true
},
js: {
files: ['app/js/**/*.js'],
tasks: ['jshint']
}
}
});
grunt.registerTask('server',[
'connect',
'watch'
]);
关于javascript - Grunt - 实时重新加载不适用于 grunt-contrib-watch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19740827/