javascript - 我如何通过一个命令让 grunt 观看和 livereload - Gruntjs

标签 javascript gruntjs

这是我的 Gruntfile.js: /*全局模块*/

module.exports = function(grunt) {
  'use strict';

  // Load Grunt tasks declared in the package.json file
  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
        }
      }
    },
    less: {
      development: {
        files: {
          'app/css/easier.css': 'app/less/easier.less'
        }
      }
    },
    watch: {
      less: {
        files: ['app/less/easier.less'],
        tasks: ['less']
      },
      scripts: {
        files: ['app/**/*.js'],
        options: {
          spawn: false,
          livereload: true
        }
      }
    }
  });

  grunt.registerTask('server',[
    'connect',
    'watch'
  ]);
};

我运行 grunt server 命令,我的文件得到了应有的服务。在另一个控制台中,我运行 grunt watch,然后如果有任何更改,它会在浏览器中自动更改。是什么让这只用命令 grunt server 完成所有这些。我认为通过在服务器任务中添加任务 watch 可以解决这个问题,但它不起作用。我尝试仅通过 watch 任务在 Chrome 中启用 livereload,但我收到一条警告,提示 Could not connect to LiveReload server。请确保 LiveReload 2.3(或更高版本)或其他兼容服务器正在运行。我错过了什么?

最佳答案

设置keepalivefalse,否则脚本会阻塞,不会执行watch任务。

关于javascript - 我如何通过一个命令让 grunt 观看和 livereload - Gruntjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19769808/

相关文章:

javascript - 无法将从 Blender 导出的对象加载到 Three.js 中?

javascript - Kendo上传验证消息位置

javascript - D3 v4 xAxis 缩放将 x 返回为 NaN 使得 rescale(x) 无法完成

gruntjs - 将参数从别名任务传递给Grunt任务

gruntjs - Grunt-命令行参数,不起作用

javascript - 我怎样才能在滚动上获得 "ballooning"效果?

asp.net - Google Protocol Buffers 或类似的 .net/javascript

node.js - 如何设置 grunt 文件来监视和编译 less 文件

javascript - 如何从 grunt.registerTask() 运行特定任务?

javascript - 多次更改 Grunt