简体   繁体   English

咕watch的手表多次执行任务

[英]grunt watch executes tasks multiple times

I've the following Grunfile.js File: 我有以下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']);

};

After running grunt watch and saving my scss File, the console output is the following: 运行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.

The problem is, the .scss file is compiled every time. 问题是,每次都编译.scss文件。 Even if there was no change. 即使没有变化。

I don't understand why grunt is running 3 tasks (newer:sass, newer:sass:dist, sass:dist), instead of only running the task defined under watch (newer:sass). 我不明白为什么grunt运行3个任务(newer:sass,newer:sass:dist,sass:dist),而不是仅运行watch下定义的任务(newer:sass)。

Hope someone has an idea to fix this. 希望有人有解决此问题的想法。 :) :)

I'm not positive this is the problem, but try specifying that you don't want to run all of sass , just sass:dist . 我不太肯定这是问题所在,但请尝试指定您不想运行所有sass ,而只需运行sass:dist So try: grunt.registerTask('default', ['newer:sass:dist']); 因此,请尝试: grunt.registerTask('default', ['newer:sass:dist']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM