Grunt Watch Task不触发Uglify任务

我在GAMP内部运行一个非常简单的工作stream程,在MAMP中运行。 我正在使用监视任务来触发Sass任务,该任务运行两个子任务(将展开和压缩的样式表放在不同的目录中)以及缩小/连接JavaScript文件。 Sass任务没有问题,但Watch任务不会看到任何JavaScript文件更改来触发Uglify任务。 这是我的Grunt.js文件

module.exports = function(grunt){ grunt.initConfig({ pkg : grunt.file.readJSON('package.json'), //Sass task sass:{ dev: { options: { style: 'expanded', sourcemap: 'none' }, files: { //Destination, Source 'human-readable/style-expanded.css': 'sass/style.scss', 'human-readable/bootstrap-min.css': 'sass/bootstrap.scss' } }, prod:{ options:{ style: 'compressed', sourcemap: 'none' }, files:{ //Destination, Source 'style.css': 'sass/style.scss', 'css/bootstrap.min.css': 'sass/bootstrap.scss' } } }, //Uglify task uglify:{ options:{ mangle: false, screwIE8: true }, my_target:{ files:{ //Destination, Source 'js/main.min.js': ['human-readable/main.js','js/bootstrap.min.js'] } } }, //Watch task watch: { css: { files: '**/*.scss', tasks: ['sass'] }, scripts: { files: '**/*.js', tasks: ['uglify'] } } }); grunt.loadNpmTasks('grunt-contrib-sass'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('default', ['watch']); } 

想法?

可能是你想同时观察两件事情,可能是这个问题,试试grunt-concurrent模块,它可以让你并行/并行运行grunt任务:

 grunt.loadNpmTasks('grunt-concurrent'); grunt.initConfig({ ... concurrent: { tasks: ['watch:css', 'watch:script'] } ... grunt.registerTask('default', ['concurrent']); ...