我最初的问题是让手表只针对更改的文件执行minify / uglify而不是所有内容。当它与所有东西竞争时,我必须等待几秒钟。
我终于放弃了观察并且不情愿地安装了另一个插件," grunt-newer"。
我不知道如何确定这是否有效,但第一项任务似乎已执行。
我接下来需要解决的问题是如何获得第二个任务,然后运行第三个任务。到目前为止,我只能让我的监视列表中的第一个任务工作。我已经改变了任务,总是得到同样的东西。第一个任务就完成了,然后就完成了。
这是我的grunt文件。我仍然是咕噜咕噜的新人,记住这一点。
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$/, '$1.min.js');
// grunt.config('uglify.apps.src', filepath);
// //grunt.config('uglify.apps.dest', destFilePath);
//});
};
答案 0 :(得分:0)
我认为我对“更新”的插件感到满意。
我从来没有能够让手表从注册的任务中运行多个任务,也许这是有道理的,虽然选择要观看的任务是一个很好的功能。
我只是在跑“看”,这已经足够了。