Server 如何让咕噜服务任务与手表一起工作?

Server 如何让咕噜服务任务与手表一起工作?,server,gruntjs,Server,Gruntjs,我最近安装并运行了一个it,但我似乎不能让它与我的手表任务同时运行?在我的grunt文件中,如果在监视之前注册服务任务,则服务器会启动,但监视任务不会…反之亦然。这是随附的serve软件包、Im使用和Grunt文件: Gruntservice和Gruntwatch都是阻塞任务。你可以使用一个插件在不同的线程中同时运行这两个插件 此外,您还可以使用grunt concurrent并行运行uglify和sass任务,这可能会缩短构建时间 module.exports = function(grun

我最近安装并运行了一个it,但我似乎不能让它与我的手表任务同时运行?在我的grunt文件中,如果在监视之前注册服务任务,则服务器会启动,但监视任务不会…反之亦然。这是随附的serve软件包、Im使用和Grunt文件:


Grunt
service
和Grunt
watch
都是阻塞任务。你可以使用一个插件在不同的线程中同时运行这两个插件

此外,您还可以使用
grunt concurrent
并行运行uglify和sass任务,这可能会缩短构建时间

module.exports = function(grunt) {

    // 1. All configuration goes here 
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        concat: {   
            dist: {
                src: [
                    'js/libs/*.js', // All JS in the libs folder
                    'js/global.js'  // This specific file
                ],
                dest: 'js/build/production.js',
            }
        },

        uglify: {
            options: {
              mangle: false
            },
            my_target: {
              files: {
                'js/build/production.min.js': ['js/build/production.js']
              }
            }
          },

        imagemin: {
            dynamic: {
                files: [{
                    expand: true,
                    cwd: 'images/',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: 'images/build/'
                }]
            }
        },

        sass: {
            //options: {  
            //    style: 'compressed'
            //},
            dist: {
              files: [{
                expand: true,
                cwd: 'css',
                src: ['*.scss'],
                dest: 'css/build/',
                ext: '.css'
              }]
            }
          },

        serve: {
            options: {
                port: 9000
            }
        },

        watch: {
            options: {
                livereload: true,
            },              
            css: {
                files: ['css/**/*.scss'],
                tasks: ['sass'],
                options: {
                    spawn: false,
                }
            },            
            scripts: {
                files: ['js/*.js'],
                tasks: ['concat', 'uglify'],
                options: {
                    spawn: false,
                },
            } 
        }



    });

    // Load all Grunt tasks automatically wihtout having to enter manaually
    require('load-grunt-tasks')(grunt);

    grunt.registerTask(
        'default',
            [
                'concat', 
                'uglify', 
                'sass', 
                'serve',
                'watch'
            ]
    );

};
concurrent: {
    target1: ['serve', 'watch'],
}

//aslo update your default task
grunt.registerTask(
    'default',
        [
            'concat', 
            'uglify', 
            'sass', 
            'concurrent:target1'
        ]
);