gruntjs - grunt-contrib-watch : { tinylr: "Welcome", 版本: "0.0.4"}

标签 gruntjs grunt-contrib-watch

我正在尝试使用 grunt-contrib-watch 和 grunt-contrib-compass 来让 grunt 工作。

到目前为止,我的 Gruntfile 看起来像这样:

module.exports = function (grunt){

    grunt.initConfig({

    compass : {

        dist : {
        options : {
            debugInfo : 'true'          
        }

        }

    },

    watch : {       
        files : ['*.html', 'js/*', 'sass/*'],
        task : ['compass'],
        options : {
        livereload: true,
        port : 35729
        }       
    }

    });


    grunt.loadNpmTasks('grunt-contrib-watch') ;
    grunt.loadNpmTasks('grunt-contrib-compass') ;

    grunt.registerTask('default', ['watch'])

} ;

我正在使用 chrome live-reload 扩展程序。

如果我随后运行“grunt -v”,我可以看到 grunt 按预期监视我的 html 和 sass 文件。正如预期的那样,我的浏览器选项卡会自动重新加载。

在浏览器选项卡中,我转到此地址:

http://localhost:35729

但是,在我的浏览器中,我只在加载和重新加载时看到这个:

{
tinylr: "Welcome",
version: "0.0.4"
}

我没有看到我的 index.html。只是对象。

我需要做什么才能看到我的网站?

最佳答案

http://localhost:35729是实时重新加载服务器的地址,而不是您的网站。您的网站仍然需要从它自己的地址/端口提供服务,例如 http://localhost:8000 .通过 grunt-contrib-connect 任务、其他一些 node.js 服务器或提供文件 apache/nginx 的服务器。

http://localhost:35729仅用于将实时重新加载脚本加载到您的页面中:<script src="http://localhost:35729/livereload.js"></script>然后根据更改将使用网络套接字触发和更新您网站上的页面。

关于gruntjs - grunt-contrib-watch : { tinylr: "Welcome", 版本: "0.0.4"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19509186/

相关文章:

ruby - 生成源映射时出错 - grunt 和 sass 配置

gruntjs - 以编程方式运行 Compass Grunt 任务

gruntjs - 如何让 grunt-watch 在不同的构建任务下实时重新加载 HTML 更改

javascript - 纠错后 Grunt watch 运行得更少

gruntjs - grunt-contrib-watch 导致超出最大调用堆栈大小

node.js - 使用 grunt-express-server 和 grunt-contrib-watch 进行实时重新加载

grunt-browserify 找不到 jquery 模块

javascript - 收到 grunt-istanbul 错误 : No coverage information was collected

javascript - 如何构建 polymer 元素?

javascript - 观察事件上的 grunt 动态任务