javascript - 浏览器未使用 Grunt Livereload 重新加载

标签 javascript gruntjs livereload

我试图在更改文件时添加 broser 的 livereload,但浏览器没有重新加载,我不明白为什么,我都像描述的那样 here ,当我 tun 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 或任何文件,请告诉我。谢谢!

这是我的 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 配置中相同的 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'
    }
}

关于javascript - 浏览器未使用 Grunt Livereload 重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30615554/

相关文章:

javascript - 咕噜声 : Task "default" not found

gruntjs - 如何在 Yeoman 中通过 Livereload 更改自动打开页面?

javascript - grunt-contrib-watch livereload 不重新加载

node.js - 以编程方式控制 Jetbrains 内置服务器

javascript - 针对 DOM 的前一个 li 元素不起作用

javascript - 异步谷歌分析 [Javascript 高尔夫]

angularjs - 使用 Grunt 时删除包 "was not injected in your file"的警告?

javascript - 403 从本地主机提供资源

javascript - 避免快速 REST API 内的 Controller 文件中的重复函数

javascript - 如何使用 JavaScript 将字符添加到字符串的随机空间?