【问题标题】:Grunt executes multiple times, creates infinite loopGrunt 执行多次,创建无限循环
【发布时间】:2016-04-09 16:57:18
【问题描述】:

我们正在与 GIT 上的其他几个开发人员一起开展一个项目,使用相同的存储库,它与其他所有人都可以正常工作。但是,当我运行 grunt 时,它会执行多次,似乎陷入了无限循环,而我实际上并没有进行任何更改。它只发生在我的另一台电脑上 我正在考虑也许我需要安装其他东西。 我删除了节点、npm 并重新安装了我也用于更新的自制软件。节点 v5.3.0,npm 3.3.12 跑小牛队。

我错过了什么?

这是循环:

    Reloading watch config...

Running "watch" task
Waiting...
>> File "Gruntfile.js" changed.
>> File "js/all-js/bootstrap-hover-dropdown.min.js" changed.
>> File "js/all-js/site.js" changed.
Running "uglify:build" (uglify) task
>> 1 file created.

Done, without errors.
Completed in 3.740s at Tue Jan 05 2016 13:11:07 GMT-0500 (ECT) - Waiting...
[BS] File changed: js/site.min.js

Reloading watch config...

Running "watch" task
Waiting...
>> File "js/all-js/bootstrap.js" changed.
>> File "Gruntfile.js" changed.
Running "uglify:build" (uglify) task
>> 1 file created.

Done, without errors.
Completed in 1.869s at Tue Jan 05 2016 13:11:10 GMT-0500 (ECT) - Waiting...
[BS] File changed: js/site.min.js
>> File "js/all-js/bootstrap-hover-dropdown.min.js" changed.
Running "uglify:build" (uglify) task
>> 1 file created.

Done, without errors.
Completed in 1.885s at Tue Jan 05 2016 13:12:04 GMT-0500 (ECT) - Waiting...
[BS] File changed: js/site.min.js

Reloading watch config...

Running "watch" task
Waiting...
>> File "Gruntfile.js" changed.

这是我的 Gruntfile.js:

    module.exports = function(grunt) {

//Get all tasks from the package.json file
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),    

    /* Concurrent Task */          

    concurrent: {
        watch: {
            tasks: ['watch', 'compass:dist', 'browserSync'],
            options: {
                logConcurrentOutput: true
            }
        }
    },

    /* SASS task */

     compass: {
        dist: {
            options: {
              sassDir: ['SASS/'],
              cssDir: ['css/'],
              environment: 'development', /* development | production */
              importPath: ['SASS/'],
              outputStyle: 'compressed', /* expanded for development | compressed for production */
              watch: true,
              sourcemap: true
            },
        },
        live: {
            options: {
              sassDir: ['SASS/'],
              cssDir: ['css/'],
              environment: 'production', /* development | production */
              importPath: ['SASS/'],
              outputStyle: 'compressed', /* expanded for development | compressed for production */
              watch: false,
              force: true,                      
            },
        },          
    },      

    /* Javascript Tasks */

    uglify: {
        // Uglify files

        build: {
            src: [
                'js/all-js/bootstrap.js',
                'js/all-js/site.js'
            ],
            dest: 'js/site.min.js'
        }

    },

    /* Run tasks when needed */

    watch: {            
        js: {
            files: ['js/all-js/*.js'],
            tasks: ['uglify'],
            options: { livereload: true }
        },
        gruntfile: {
            files: ['Gruntfile.js'],
            options: {reload: true}
        }
    },

    /* Browser Reload with BrowserSync */

    browserSync: {
        bsFiles: {
            src : [
                'css/**/*.css',
                'js/site.min.js',
                '**/*.php'
            ]
        },
    }       


});

// Where we tell Grunt what to do when we type "grunt" into the terminal.

grunt.registerTask('default', ['concurrent:watch']);
grunt.registerTask('live', ['compass:live']);

};

这是我的 package.json 文件:

    {
      "name": "ourframework",
      "version": "0.1.0",
      "devDependencies": {
      "grunt": "~0.4.1",
      "grunt-contrib-compass": "*",
      "grunt-browser-sync": "*",
      "grunt-contrib-watch": "*",
      "grunt-concurrent": "*",
      "grunt-contrib-uglify": "*",      
      "matchdep": "*"
    }
   }

【问题讨论】:

  • 我刚刚在另一台计算机上测试了这个确切的设置并且运行良好!
  • 请在下面阅读我的答案——它会一直运行良好,因为没有问题。您看到的“循环”只是稍后发生的编译,当某些事情发生变化时。

标签: node.js gruntjs npm


【解决方案1】:

查看 grunt 输出中的时间戳,例如:

Completed in 3.740s at Tue Jan 05 2016 13:11:10
Completed in 1.885s at Tue Jan 05 2016 13:12:04

请注意,这些编译相隔一分钟 - 您正在运行 grunt watch 任务。这将监视一组指定的文件并在有任何更改时重新运行任务。

没有“循环”——它只会在每次发生变化时重新编译,这通常是可取的。

可以看到你的默认任务设置为concurrent:watch

grunt.registerTask('default', ['concurrent:watch']);

因此,如果您只输入grunt,它将运行该任务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 2013-04-05
    相关资源
    最近更新 更多