我如何只用一个命令让咕噜咕噜观看和实时加载 - 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. Please make sure that LiveReload 2.3 (or later) or another compatible server is running.我错过了什么?

keepalive设置为 false ,否则脚本将阻塞并且不会执行watch任务。

最新更新