2015-08-08 103 views
0

我正在咕噜咕噜咕噜咕噜咕噜,试图通过咕噜声和连接来运行我的网站。 我有这样的gruntfile:如何让livereload与grunt一起工作?

module.exports = function(grunt) { 

    // Project configuration. 
    grunt.initConfig({ 

    pkg: grunt.file.readJSON('package.json'), 
    connect: { 
     options: { 
     port: 9000, 
     // Change this to '0.0.0.0' to access the server from outside. 
     hostname: 'localhost', 
     livereload: 35729 
     }, 
     livereload: { 
     options: { 
      open: true, 
      middleware: function (connect) { 
      return [ 
       connect.static('.tmp'), 
       connect().use(
       '/bower_components', 
       connect.static('./bower_components') 
      ), 
       connect.static(appConfig.app) 
      ]; 
      } 
     } 
     } 
    }); 

    // Load the plugin that provides the "uglify" task. 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.loadNpmTasks('grunt-contrib-connect'); 

    // Default task(s). 
    grunt.registerTask('default', ['connect:livereload','watch']); 

}; 

问题是,当我运行的呼噜声,我得到一个错误:

Running "connect:livereload" (connect) task 
Warning: undefined is not a function Use --force to continue. 

Aborted due to warnings. 

我怎样才能得到咕噜运行?

+0

运行'grunt --verbose'你会得到更多的错误信息。 – Vishwanath

+0

是否定义了'appConfig.app'? –

回答

1

我可以看到你打电话给appConfig.app(可能来自yeoman生成项目的c/p),但你从来没有创建它。这可能是一个暗示,因为你的其他代码似乎是正确的。

0

在我目前正在研究的项目中,我决定将插件更改为BrowserSync。配置和完成“工作”很容易。

BrowserSync网站:http://www.browsersync.io/docs/grunt/。 配置很简单,它在网站上给出,所以我不打算在这里复制它。也许如果你在grunt-contrib-connect有困难,你可以试试这个。