首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带LiveReload的表不工作

带LiveReload的表不工作
EN

Stack Overflow用户
提问于 2013-11-21 11:58:08
回答 5查看 18.3K关注 0票数 14

我不能让LiveReload和Grunt一起工作。我用的是咕噜-表。当Grunt正在监视指定的文件时,浏览器中没有重新加载任何内容。所以我会看看:

代码语言:javascript
复制
Running "watch" task
Completed in 0.203s at Thu Nov 21 2013 00:59:59 GMT-0500 (EST) - Waiting...
OK
>> File "views/index.html" changed.

但是浏览器窗口不更新。我使用的是LiveReload 2.0.9。对如何让它运行有什么建议吗?

Gruntfile.js

代码语言:javascript
复制
module.exports = function(grunt) {

  'use strict';

  grunt.initConfig({
    express: {
      dev: {
        options: {
          script: './app.js'
        }
      }
    },
    watch: {
      tasks:  [ 'express:dev' ],
      options: {
        livereload: true,
        nospawn: true
      },
      files: [
        './views/index.html',
        './preprocessing/css/style.scss'
      ]
    }
  });

  grunt.loadNpmTasks('grunt-express-server');
  grunt.loadNpmTasks('grunt-contrib-watch');

  grunt.registerTask('default', [ 'express:dev', 'watch' ]);
};
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-11-21 12:07:03

默认情况下,您所缺少的只是在文档中包括livereload脚本<script src="//localhost:35729/livereload.js"></script>

如果您希望避免手动执行此操作,则可以使用肝连接中间件。

Gruntfile.js,这是使用我链接到的中间件进行监视和肝读取的设置。

票数 21
EN

Stack Overflow用户

发布于 2014-07-09 10:49:03

如果不将livereload.js添加到pages.You中,可以使用chrome插件:

https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei

使用此插件.when页面加载,单击插件ico,确保点changed.Then页面源将自动添加

票数 0
EN

Stack Overflow用户

发布于 2022-02-23 01:08:48

您可以使用Grunt 实时发布浏览器页面

GitHub

样例

代码语言:javascript
复制
const 
  LiveReload = require("live-reload-bp");
  // webServer = require('./web-server');

var 
  liveReload;

// webServer();

module.exports = function(grunt) {

  grunt.initConfig({
  
    liveReload: {
      run: {
        options: {
          host: '127.0.0.1',
          port: '8080'
        }
      },    
      js: {
        options: {}
      },
    },

    uglify: {
        build777: {
          files: [{
            expand: true,
            cwd: 'src',
            src: 'js/**/*.js',
            dest: 'dest'
          }]
        }
    },

    watch: {
      options: {
        spawn: false 
        // It is recommended to disable `false` or not use 'grunt-contrib-watch' 
        // or perhaps even Grunt. Because it works very very slowly.
      },
      js: {
          files: ['src/**/*.js'],
          tasks: ['uglify', 'liveReload:js']
      },       
    },

  });


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


  // Register Task
  grunt.registerTask('start', ['liveReload:run', 'watch']);


  grunt.registerMultiTask('liveReload', '', function() {
      if (grunt.fail.errorcount > 0 || grunt.fail.warncount > 0) {
          return false;
      }

      if(this.target === 'run'){
          liveReload = new LiveReload(this.data.options);
          liveReload.run();
      }else{
          liveReload.reloadPage();
      }
  });

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20120412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档