2014-04-04 132 views
0

停止我咕嚕文件是這樣的:咕嚕-的contrib-CONNECT:咕嚕服務器時,瀏覽器會打開

module.exports = function(grunt){ 

    grunt.loadNpmTasks('grunt-open'); 
    grunt.loadNpmTasks('grunt-contrib-connect'); 

    grunt.initConfig({ 
     pkg: grunt.file.readJSON('package.json'), 

     connect: { 
      dev: { 
       options: { 
        port: 8999, 
        livereload: 35729, 
        hostname: 'localhost' 
       }, 
       livereload: { 
        options: { 
         open: { 
          target: 'http://localhost:8999' 
         }, 
         base: [ 
          'src/main' 
         ] 
        } 
       } 
      } 

      }, 

      open: { 
       dev: { 
        path: 'http://localhost:<%= connect.dev.options.port %>' 
       } 
      } 
     }); 

     grunt.registerTask('default', ['connect:dev', 'open:dev']); 
} 

但我的問題是,每當browseropens,該服務器在此之前,停止。

請幫忙。提前致謝。

回答

1

您可以添加監視的任務,將監視更改的文件,並保持服務器最多:

watch: { 
     options: { 
      nospawn: true 
     }, 
     livereload: { 
      options: { 
       livereload: LIVERELOAD_PORT 
      }, 
      files: [ 
       'src/main/*.js', 
       'src/main/*.html' 
      ] 
     } 
}, 

,然後更改任務是:

grunt.registerTask('default', ['connect:dev', 'open:dev', 'watch']);