2

を使用して変更したときに、Grunt に js ファイルをリロードさせようとしていますgrunt-contrib-watch。これが私のものGruntfileです:

module.exports = function(grunt) {

  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  grunt.initConfig({

     connect: {
      all: {
        options:{
          port: 9000,
          hostname: "0.0.0.0",
          base: 'app',
          keepalive: true,
          middleware: function(connect, options) {

            return [

              require('grunt-contrib-livereload/lib/utils').livereloadSnippet,

              connect.static(options.base)
            ];
          }
        }
      }
    },
    open: {
      all: {
        path: 'http://localhost:<%= connect.all.options.port%>'
      }
    },
    watch: {
      options: {
        livereload: true
      },
      js: {
        files: ['app/js/**/*.js'],
        tasks: ['jshint'],
      }
    }
  });

  // Creates the `server` task
  grunt.registerTask('server',[
    'open',
    'livereload-start',
    'connect',
    'watch'
  ]);
};

js ファイルを変更しても何も起こりません。どんな助けでも素晴らしいでしょう。

4

1 に答える 1

5

これまでミドルウェアでを使用したlivereloadSnippetことがないので、何が問題なのかわかりません。しかし、通常の LiveReload セットアップだけが必要な場合は、プラグインlivereloadが提供するオプションを利用できます。grunt-contrib-connect

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,
        open: true
      }
    }
  },
  watch: {
    options: {
      livereload: true
    },
    js: {
      files: ['app/js/**/*.js'],
      tasks: ['jshint']
    }
  }
});

grunt.registerTask('server',[
  'connect',
  'watch'
]);
于 2013-11-03T09:14:04.530 に答える