我试图在更改我的文件时添加浏览器的liverload,但浏览器没有重新加载,我不能得到为什么,我做的都像这里描述的,当我打开浏览器grunt,然后当更改index.html
时,在控制台获得
Waiting...
>> File "index.html" changed.
Completed in 0.000s at Wed Jun 03 2015 11:45:24 GMT+0300 (EEST) - Waiting...
>> File "index.html" changed.
Completed in 0.000s at Wed Jun 03 2015 11:54:11 GMT+0300 (EEST) - Waiting...
>> File "index.html" changed.
Completed in 0.000s at Wed Jun 03 2015 12:01:30 GMT+0300 (EEST) - Waiting...
但是浏览器没有重新加载,我做错了什么?也许我错过了什么?我试图谷歌问题,但没有得到任何有用的结果…如果你需要我的文件,就告诉我。谢谢!
我的Gruntfile.js:
module.exports = function(grunt) {
// Load Grunt tasks declared in the package.json file
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Configure Grunt
grunt.initConfig({
// Grunt express - our webserver
// https://github.com/blai/grunt-express
express: {
all: {
options: {
bases: ['var\www\megapolis'],
port: 8080,
hostname: "localhost",
livereload: true
}
}
},
// grunt-watch will monitor the projects files
// https://github.com/gruntjs/grunt-contrib-watch
watch: {
all: {
files: '**/*.html',
options: {
livereload: true
}
}
},
// grunt-open will open your browser at the project's URL
// https://www.npmjs.org/package/grunt-open
open: {
all: {
path: 'http://localhost/megapolis/index.html'
}
}
});
// Creates the `server` task
grunt.registerTask('server', [
'express',
'open',
'watch'
]);
};
可能原因是您的grunt-open插件没有配置与express服务器相同的端口。grunt-open插件使用默认的80端口,而express在8080上配置。
尝试添加与express configuration中相同的8080端口:
// grunt-open will open your browser at the project's URL
// https://www.npmjs.org/package/grunt-open
open: {
all: {
path: 'http://localhost:8080/megapolis/index.html'
}
}