简体   繁体   中英

Grunt so slow with watch multiple less tasks

I have a simple less files with very little contents but the compile time varies from 10 - 27s. Any ideas as to why? Is it my machine or the grunt settings that I am missing? Do I need to clear some sort of cache?

Gruntfile.js contents

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 contents

{
  "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 contents

body{
    background: red;
}


/* End of Main */

This grunt-timer module may help you track it down:

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

If you find a particular task takes a while, you could try grunt-changed to only build each task when a change occurs for it:

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

Maybe it's not the compilation process taking so long but the loading of the modules; this is the cause most of the time.

Take a look at this post: even if it doesn't solve your problem it might give you a hint on what is taking so long.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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