【发布时间】:2014-07-10 10:52:39
【问题描述】:
我有以下 Grunfile.js 文件:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'css/build/style.css': 'css/style.scss'
}
}
},
watch: {
stylesheets: {
files: ['css/*.scss'],
tasks: ['newer:sass']
}
}
});
// Load the plugin that compiles sass
grunt.loadNpmTasks('grunt-contrib-sass');
// watch for, and run grunt if files change
grunt.loadNpmTasks('grunt-contrib-watch');
// Plugin for Grunt tasks to run with newer files only.
grunt.loadNpmTasks('grunt-newer');
// Grunt Tasks:
grunt.registerTask('default', ['newer:sass']);
};
运行 grunt watch 并保存我的 scss 文件后,控制台输出如下:
Running "watch" task
Waiting...
>> File "css\style.scss" changed.
Running "newer:sass" (newer) task
Running "newer:sass:dist" (newer) task
Running "sass:dist" (sass) task
File css/build/style.css created.
Running "newer-postrun:sass:dist:1:D:\xampp\htdocs\grunt-test\node_modules\grunt-newer\.cache" (newer-postrun) task
Done, without errors.
问题是,.scss 文件每次都会编译。即使没有变化。
我不明白为什么 grunt 运行 3 个任务(newer:sass、newer:sass:dist、sass:dist),而不是只运行 watch 下定义的任务(newer:sass)。
希望有人有解决此问题的想法。 :)
【问题讨论】:
标签: javascript gruntjs grunt-contrib-watch