Skip to content

Commit

Permalink
Optimize grunt (RocketMap#187)
Browse files Browse the repository at this point in the history
* Load "npmtasks" on demand instead of _every_ time; speeds up subset watch tasks dramatically

* Split json smushing apart from js smushing so watch can be more focused

* Stop watching html files; we are not using this and its catching a lot of useless updates

* Watch WAY less files here; this trims us down from 1500->50 watches.

* Allow calling "npm run grunt -- grunt args here" for arbitrary grunt command running in context

* Utilize grunt-newer to avoid recompiling files which have not changed during watch
  • Loading branch information
chuyskywalker authored Aug 9, 2016
1 parent 631915a commit 5ea69f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
36 changes: 14 additions & 22 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = function(grunt) {

// load plugins as needed instead of up front
require('jit-grunt')(grunt);

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

Expand Down Expand Up @@ -76,15 +79,16 @@ module.exports = function(grunt) {
interval: 1000,
spawn: true
},
src: {
files: ['**/*.html'],
options: { livereload: true }
},
js: {
files: ['**/*.js', '**/*.json', '!node_modules/**/*.js', '!static/dist/**/*.js', '!static/dist/**/*.json'],
files: ['static/js/**/*.js'],
options: { livereload: true },
tasks: ['js-lint', 'js-build']
},
json: {
files: ['static/data/*.json', 'static/locales/*.json'],
options: { livereload: true },
tasks: ['json']
},
css: {
files: '**/*.scss',
options: { livereload: true },
Expand All @@ -105,24 +109,12 @@ module.exports = function(grunt) {
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-html-validation');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-minjson');

grunt.registerTask('js-build', ['babel', 'uglify', 'minjson']);
grunt.registerTask('css-build', ['sass', 'cssmin']);
grunt.registerTask('js-lint', ['eslint']);
grunt.registerTask('js-build', ['newer:babel', 'newer:uglify']);
grunt.registerTask('css-build', ['newer:sass', 'newer:cssmin']);
grunt.registerTask('js-lint', ['newer:eslint']);
grunt.registerTask('json', ['newer:minjson']);

grunt.registerTask('build', ['clean', 'js-build', 'css-build']);
grunt.registerTask('build', ['clean', 'js-build', 'css-build', 'json']);
grunt.registerTask('lint', ['js-lint']);
grunt.registerTask('default', ['build', 'watch']);

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
"grunt-minjson": "latest",
"grunt-sass": "latest",
"grunt-unused": "latest",
"grunt-usemin": "latest"
"grunt-usemin": "latest",
"grunt-newer": "^1.2.0",
"jit-grunt": "^0.10.0"
},
"scripts": {
"postinstall": "grunt build",
"build": "grunt build",
"watch": "grunt default",
"lint": "grunt lint"
"lint": "grunt lint",
"grunt": "grunt"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 5ea69f1

Please sign in to comment.