Last active
December 16, 2015 08:48
-
-
Save luissquall/5408257 to your computer and use it in GitHub Desktop.
Apply tasks only to changed files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global module:false*/ | |
module.exports = function(grunt) { | |
// Load tasks | |
grunt.loadTasks('util/grunt'); | |
// Load vendors tasks | |
grunt.loadNpmTasks('grunt-contrib-compass'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
// Project configuration | |
grunt.initConfig({ | |
compass: { | |
dist: { | |
options: { | |
config: 'config.rb' | |
} | |
} | |
}, | |
uglify: { | |
dist: { | |
expand: true, | |
cwd: 'app/webroot/js/src/', | |
src: ['**/*.js'], | |
dest: 'app/webroot/js/build/' | |
} | |
}, | |
jshint: { | |
dist: { | |
src: ['app/webroot/js/src/**/*.js'] | |
} | |
}, | |
watch: { | |
options: { | |
nospawn: true | |
}, | |
stylesheets: { | |
files: 'app/webroot/css/src/**/*.scss', | |
tasks: ['compass'] | |
}, | |
scripts: { | |
files: 'app/webroot/js/src/**/*.js', | |
tasks: ['jshint', 'uglify'] | |
} | |
} | |
}); | |
grunt.event.on('watch', function(action, filepath) { | |
if (grunt.file.isMatch(grunt.config('watch.stylesheets.files'), filepath)) { | |
grunt.config('compass.dist.options.specify', [filepath]); | |
} | |
if (grunt.file.isMatch(grunt.config('watch.scripts.files'), filepath)) { | |
var uglifySrc = filepath.replace(grunt.config('uglify.dist.cwd'), ''); | |
grunt.config('jshint.dist.src', [filepath]); | |
grunt.config('uglify.dist.src', [uglifySrc]); | |
} | |
}); | |
// Default task. | |
grunt.registerTask('default', ['compass', 'jshint', 'uglify']); | |
}; |
it seems doesn't work
doesn't work either
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you @crdx. I'm updating the example to reflect your suggestion.