Grunt 麻烦 运行 多个任务

Grunt trouble running multiple tasks

我最初的问题是让手表只对更改的文件而不是所有内容执行 minify/uglify。当它 运行 反对一切时,我必须等待几秒钟。

我终于放弃了watch,无奈又安装了一个插件,"grunt-newer"。

我不知道如何判断这是否有效,但第一个任务似乎已执行。

接下来我要解决的问题是如何把第二个任务和第三个任务拿到运行。到目前为止,我只能让我的监视列表中的第一个任务工作。我已经调换了任务,但总是得到同样的结果。第一个任务 运行s 然后就完成了。

这是我的 g运行t 文件。我还是 g运行t 的新手,记住这一点。

module.exports = function (grunt) {

    grunt.initConfig({
        distFolder: 'core/dist',

        pkg: grunt.file.readJSON('package.json'),
        // Task configuration.
        ngAnnotate: {
            options: {
                singleQuotes: true,
            },
            mashupCore: {
                files: {
                    '': ['core/**/*.js', '!core/lib/**/*', '!core/dist/**/*']
                },
            }
        },
        uglify: {
            options: {
                sourceMap: true,
            },
            dist: {
                files: [
                    {
                        expand: true,
                        src: ['<%= distFolder %>/**/*.js', '!<%= distFolder %>**/*.min.js'],
                        dest: '',
                        ext: '.min.js',
                        extDot: 'last'
                    }
                ]
            },
            apps: {
                files: [
                    {
                        expand: true,
                        src: ['core/apps/**/*.js', '!**/*.min.js', '!core/apps/**/route.config.js'],
                        dest: '',
                        ext: '.min.js',
                        extDot: 'last'
                    }
                ]
            },
            coreroot: {
                files: [
                    {
                        expand: true,
                        src: ['core/*.js', '!**/*.min.js'],
                        dest: '',
                        ext: '.min.js',
                        extDot: 'last'
                    }
                ]
            }
        },
        cssmin: {
            all: {
                files: [
                    {
                        expand: true,
                        src: ['core/**/*.css', '!**/*.min.css'],
                        dest: '',
                        ext: '.min.css',
                        extDot: 'last'
                    }
                ]
            }
        }

        ,
        concat: {
            options: {
                separator: ';',
            },
            routeconfig: {
                src: ['core/config/route.config.js', 'core/apps/**/route.config.js', '!core/lib/**/*', '!core/dist/**/*'],
                dest: '<%= distFolder %>/route.config.js',
            },
            coreservices: {
                src: ['core/common/services/**/*', '!core/lib/**/*', '!core/dist/**/*'],
                dest: '<%= distFolder %>/core.services.js',
            },

        },
        clean: {
            dist: {
                src: ['<%= distFolder %>/**/*.*/', '<%= distFolder %>/**/*.*']
            }
        }
        //, jshint: {
        //    all: {
        //        src: ['Gruntfile.js', 'core/**/*.js', '!core/dist/**/*', '!**/*.min.js', '!core/lib/**/*']
        //        , dest: 'output.js'
        //    }
        //}
        ,
        watch: {
            apps: {
                files: ['core/apps/**/*.js', '!**/*.min.js', '!core/apps/**/route.config.js'],
                tasks: ['uglify:apps'],
                options: {
                    spawn: false,
                },
            },
            dist: {
                files: ['core/common/services/**/*','core/config/route.config.js', 'core/apps/**/route.config.js', '!core/lib/**/*', '!core/dist/**/*'],
                tasks: ['clean:dist','concat:routeconfig', 'concat:coreservices', 'uglify:dist'],
                options: {
                    spawn: false,
                },
            },
        },

    });

    // Load modules, register tasks
    // grunt.loadNpmTasks('ngAnnotate');
    grunt.loadNpmTasks('grunt-ng-annotate');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-newer');


    // this annotate tasks only needs run periodically.  It processes all files even if they have already been properly annotated.
    // So it's worth removing to save build time at the developer machine.
    // grunt.registerTask('default', ['ngAnnotate']);
    // grunt.registerTask('default', ['uglify']);

    // ------------------------------------------------------------------------------------------
    // grunt default
    grunt.registerTask('default', [
        'annotate', 'clean:dist', 'concat:routeconfig', 'concat:coreservices',
        'uglify:dist', 'uglify:apps', 'uglify:coreroot', 'cssmin:all'
    ]);
    // 1. Annotates all but 'lib' directory.
    // 2. Cleans out the "dist" directory
    // 3. Concatinates together all files named route.config.js into a single file route.config.min.js
    // 4. Uglify creates maps
    // ------------------------------------------------------------------------------------------

    grunt.registerTask('annotate', ['ngAnnotate']);
    grunt.registerTask('clean_dist', ['clean:dist']);
    //grunt.registerTask('watchcode', ['watch:dist', 'watch:apps']);
    grunt.registerTask('watchcode', ['newer:watch:apps', 'newer:watch:dist']);


    //grunt.event.on('watch:apps', function (action, filepath, target) {
    //    //change the source and destination in the uglify task at run time so that it affects the changed file only
    //    var destFilePath = filepath.replace(/(.+)\.js$/, '.min.js');
    //    grunt.config('uglify.apps.src', filepath);
    //    //grunt.config('uglify.apps.dest', destFilePath);

    //});
};

我觉得我对 "newer" 插件很满意。

我一直无法让手表从已注册的任务中 运行 多个任务,这也许是有道理的,尽管选择要观看的任务是一个不错的功能。

我只是 运行宁 "watch" 已经足够好了。