W
W
whitebookman2013-12-20 13:38:16
Grunt.js
whitebookman, 2013-12-20 13:38:16

How fast does grunt work for you and what did you do for it?

Recently I discovered grunt and there was no limit to joy until all dependencies were registered and everything was configured for itself. With all kinds of tasks in watch mode, the execution time is ~17 seconds. If you leave only watch in Gruntfile and compile less to css ~ 3 sec.
If it's possible to somehow speed up grunt, I'd be happy to hear about it in the form of your answer, an angry link to the documentation/forum/whatever. I can’t find it myself (
Of course, my laptop is weak, but does grunt really need a lot?
Actually laptop: win7, atom 1.5, 2gb RAM
Gruntfile

module.exports = function(grunt) {

  grunt.initConfig({
    uglify: {
      options: {
        report: 'gzip',
        compress: {
          dead_code: true,
          sequences: true,
          evaluate: true,
          booleans: true,
          loops: true,
          if_return: true,
          join_vars: true
        }
      },
      task: {
        src: ['js/concat/concat.js'],
        dest: 'js/min/min.js'
      }
    },
    imagemin: {
      options: {
        optimizationLevel: 1,
        pngquant: true,
        progressive: false,
        interlaced: false
      },
      dynamic: {
        files: [{
          expand: true,
          cwd: 'imgs/simple/',
          src: ['*.{png,jpg,gif}'],
          dest: 'imgs/min/'
        }]
      }
    },
    sprite: {
      all: {
        src: ['imgs/forSprite/*.png'],
        destImg: 'imgs/sprite/sprite.png',
        destCSS: 'css/simple/sprite_positions.css',
        imgPath: '../../imgs/sprite/sprite.png',
        algorithm: 'binary-tree',
        padding: 2,
        engine: 'pngsmith',
        cssFormat: 'css',
        imgOpts: {
          'format': 'png'
        }
      }
    },
    less: {
      options: {
        report: 'gzip',
        sourseMap: true
      },
      dynamic: {
        files: [{
          expand: true,
          cwd: 'css/less/',
          src: ['*.less'],
          dest: 'css/simple/',
          ext: '.css',
        }]
      }
    },	
    sass: {
      options: {
        style: 'expanded'
      },
      dynamic: {
        files: [{
          expand: true,
          cwd: 'css/sass/',
          src: ['*.scss'],
          dest: 'css/simple/',
          ext: '.css',
        }]
      }
    },
    autoprefixer: {
      options: {
        browsers: ['> 1%', 'last 2 versions', 'ff 24', 'opera 12.1', 'ie 8', 'ie 7']
      },
      task: {
        src: ['css/concat/concat.css'],
        dest: 'css/concat/concat.css'
      }
    },
    cssmin: {
      option: {
        keepSpecialComments: 0,
        report: 'gzip',
      },
      task: {
        src: ['css/concat/concat.css'],
        dest: 'css/min/min.css'
      }
    },
    htmlmin: {
      options: {
        collapseBooleanAttributes: true,
        removeRedundantAttributes: true,
        collapseWhitespace: true,
        removeComments: true
      },
      dynamic: {
        files: [{
          expand: true,
          cwd: 'html/simple/',
          src: ['*.html'],
          dest: 'html/min/'
        }]
      }
    },
    replace: {
      options: {
        patterns: [
          {
          match: /\S*\.js.w*/,
          replacement: 'src="../../js/min/min.js"',
          expression: true
          },
          {
          match: /\S*\.css.w*/,
          replacement: 'href="../../css/min/min.css"',
          expression: true
          }
        ]
      },
      dynamic: {
        files: [{
          expand: true,
          flatten: true,
          src: ['html/simple/*.html'],
          dest: 'html/simple/',
        }]
      }
    },
    concat: {
      options: {
        separator: ';',
      },
      js: {
        src: ['js/libs/*.js', 'js/simple/*.js'],
        dest: 'js/concat/concat.js'
      },
      css: {
        src: ['css/libs/*.css', 'css/simple/*.css', '!css/simple/sprite_positions.css'],
        dest: 'css/concat/concat.css'
      }
    },
    watch: {
      img: {
        files: ['imgs/simple/*.{png,jpg,gif}'],
        tasks: ['imagemin:dynamic'],
        options: {
          event: ['added', 'changed']
        }
      },
      less: {
        files: ['css/less/*.less'],
        tasks: ['less:dynamic']
      },
      sass: {
        files: ['css/sass/*.scss'],
        tasks: ['sass:dynamic']
      },
      sprite: {
        files: ['imgs/forSprite/*.{png,jpg,gif}'],
        tasks: ['sprite:all'],
        options: {
          event: ['added']
        }
      },
      concatjs: {
        files: ['js/libs/*.js', 'js/simple/*.js'],
        tasks: ['concat:js']
      },
      concatcss: {
        files: ['css/libs/*.css', 'css/simple/*.css', '!css/simple/sprite_positions.css'],
        tasks: ['concat:css']
      },
      autoprefixer: {
        files: ['css/concat/concat.css'],
        tasks: ['autoprefixer:task'],
        options: {
          event: ['added', 'changed']
        }
      }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-htmlmin');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadNpmTasks('grunt-spritesmith');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-autoprefixer');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-replace');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-concat');
  
  
  grunt.registerTask(
    'default', ['replace:dynamic', 'uglify:task', 'cssmin:task', 'htmlmin:dynamic']
  );

};

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2013-12-21
@whitebookman

Grunt for such things you need very powerful hardware. My characteristics are 3 times higher and it still compiles slowly, I will soon have to upgrade just for this. Try to parallelize tasks with this https://github.com/sindresorhus/grunt-concurrent

K
Konstantin Velichko, 2014-02-15
@Zoxon

GRUNT is very slow and there is no need to upgrade the hardware. And you need to switch to GULP
If grunt builds the project in 4 seconds, let's say gulp does the same in 300 ms

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question