【问题标题】:grunt-contrib-connect: grunt server stops when browser opensgrunt-contrib-connect:当浏览器打开时 grunt 服务器停止
【发布时间】:2014-04-04 18:30:32
【问题描述】:

我有这样的 Grunt 文件:

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

但我的问题是,每当浏览器打开时,服务器都会在此之前停止。

请帮忙。提前致谢。

【问题讨论】:

    标签: gruntjs npm grunt-contrib-connect


    【解决方案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']);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-29
      • 2014-06-25
      • 2015-01-25
      • 2014-09-03
      • 2017-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多