[英]grunt watch executes tasks multiple times
我有以下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)。
希望有人有解決此問題的想法。 :)
我不太肯定這是問題所在,但請嘗試指定您不想運行所有sass
,而只需運行sass:dist
。 因此,請嘗試: grunt.registerTask('default', ['newer:sass:dist']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.