2013-11-02 59 views
2

我試圖讓Grunt重新加載我的js文件,當我使用grunt-contrib-watch更改它們時。這裏是我的GruntfileGrunt - Live重新加載不與grunt-contrib-watch一起工作

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文件沒有任何反應。任何幫助都會很棒。

+0

你有Livereload插件的瀏覽器? – DaGardner

+0

我使用的是Chrome,我有Livereload插件。 – jhamm

+0

在我的連接配置中可以使用我的'base'嗎?我也添加到我的'index.html'我的手錶配置,它也沒有找到它。 – jhamm

回答

5

我以前沒有試過在中間件中使用livereloadSnippet,所以我不確定那裏可能有什麼問題。但是,如果你只是想一個普通LiveReload設置你可以使用由grunt-contrib-connect插件提供的livereload選項:

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' 
]); 
+0

你可以簡單的在connect裏添加open:true:全部任務的選項對象,並得到相同的結果。 – ambodi

+0

將文件夾結構作爲上面的代碼轉到應用文件夾。去回購庫基地的頂部目錄:'。' 。乾杯 – fearis

相關問題