jha*_*amm 2 javascript gruntjs
我正在尝试让Grunt在我使用时更改我的js文件grunt-contrib-watch.这是我的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'
]);
};
Run Code Online (Sandbox Code Playgroud)
当我更改js文件时没有任何反应.任何帮助都会很棒.
我之前没有尝试过使用livereloadSnippet中间件,所以我不确定那里可能有什么问题.但是如果你只想要一个常规的LiveReload设置,你可以使用插件livereload提供的选项grunt-contrib-connect:
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'
]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4273 次 |
| 最近记录: |