Grunt如此缓慢,可以减少多项任务

时间:2015-07-11 01:30:25

标签: gruntjs grunt-contrib-watch grunt-contrib-less gruntfile

我的文件很少,内容很少但编译时间从10到27秒不等。任何想法为什么?是我的机器还是我失踪的咕噜声?我需要清除某种缓存吗?

Gruntfile.js内容

module.exports = function(grunt) {

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

    less: {
      development: {
        options: {
          paths: ["../css"]
        },
        files: {
          "../css/main.css": "../less/main.less",
        }
      },
      bootstrapBuild : {
        options : {
          paths: ['../css']
        },
        files : {
          "../css/bootstrap.css": "../less/bootstrap.less",          
        }
      }
    },
    watch: {
      options: {
        livereload: true
      },
      markup: {
            files: ['../*.php', '../inc/*.php'],
            options: {
                livereload: true,
            }
      },
      scripts: {
        files: ['../js/*.js'],
        tasks: [],
        options: {
          livereload: true,
          spawn: false
        },
      }, 
      mainCSS: {
        options: {
          livereload: false,
          spawn: false
        },
        files: ['../less/main.less', '../less/responsive/*.less', "../less/common.less"],
        tasks: ['less:development']
      }, 
      bootstrapBuild : {
        options: {
          livereload: false,
          spawn: false
        },
        files: ['../less/*.less', '!../less/main.less', "!../less/common.less"],
        tasks: ['less:bootstrapBuild'],
        spawn: false
      }, 
      css: {
          files: ['../css/*.css'],
          tasks: []
      }   
    }
  });

  // Less
  grunt.loadNpmTasks('grunt-contrib-less');

  // Watch
  grunt.loadNpmTasks('grunt-contrib-watch');

};

Package.json内容

{
  "name": "Project-Markup",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-nodeunit": "^0.4.1",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-contrib-less": "^0.11.4"
  }
}

main.less内容

body{
    background: red;
}


/* End of Main */

2 个答案:

答案 0 :(得分:0)

这个grunt-timer模块可以帮助您追踪它:

https://github.com/leecrossley/grunt-timer/blob/master/README.md

如果您发现特定任务需要一段时间,您可以尝试grunt-changed以仅在发生更改时构建每个任务:

https://www.npmjs.com/package/grunt-changed

答案 1 :(得分:0)

也许这不是编译过程花费这么长时间而是加载模块;这是大部分时间的原因。

看一下this帖子:即使它没有解决你的问题,它也可能会给你提示你花了这么长时间。

相关问题