node.js - Grunt 执行多次,创建无限循环

标签 node.js gruntjs npm

我们正在与 GIT 上的其他几个开发人员一起开发一个项目,使用相同的存储库,它与其他人一起工作得很好。然而,当我运行 grunt 时,它会执行多次,似乎进入了无限循环,而我实际上没有进行任何更改。仅在另一台计算机上发生在我身上 我正在考虑也许我需要安装其他东西。 我删除了 node、npm 并重新安装了自制软件,我也用它来进行更新。 Node 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": "*"
    }
   }

最佳答案

查看 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,它就会运行该任务。

关于node.js - Grunt 执行多次,创建无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34618947/

相关文章:

html - 如何使用 node.js 将数据从 html 发送到 three.js?

javascript - Node Js sequelize 原始查询更改为经纬度的 ORM

react-native - 如何使用Expo解析 "Duplicate module name: react-native"

gruntjs - gulp watch 和 browserify。观看但不会再次构建

javascript - 如何在 Django 中使用 npm 包和 ES6 功能?

laravel - 如何修复laravel 6中的错误npm run dev

node.js - node.js 是否已准备好用于中型/大型企业 Web 应用程序?

javascript - Firebase云功能-获取父 Node ,同时监听子 Node 的更改

javascript - 无法安装 gruntjs(总是创建嵌套文件夹)

node.js - 在AWS Elastic Beanstalk上的node.js项目中编译less文件并缩小js文件