【问题标题】:grunt watch executes tasks multiple timesgrunt watch 多次执行任务
【发布时间】: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


    【解决方案1】:

    我不肯定这是问题所在,但请尝试指定您不想运行所有 sass,而只运行 sass:dist。所以试试:grunt.registerTask('default', ['newer:sass:dist']);

    【讨论】:

      猜你喜欢
      • 2015-06-04
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多