Copying Files With Grunt
Overview[edit]
Steps for setting up a Grunt task to copy files when they are saved.
Prerequisites[edit]
grunt-contrib-watch
This watches for changes to files.grunt-contrib-copy
This copies files.grunt-newer
This limits the copying task to files that have been changed.
> npm install grunt-contrib-watch --save-dev > npm install grunt-contrib-copy --save-dev > npm install grunt-newer --save-dev
(N.B. that's grunt-newer and not grunt-contrib-newer)
gruntfile.js[edit]
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
/* sync whenever anything is modified */
sync: {
files: ['**/*'], /* apply to everything */
tasks: ['newer:copy']
}
},
copy: {
/* copies any file in web tree to dev sandbox */
sandbox: {
files: [{
expand: true,
src: [
'**', /* include everything */
'!/node_modules', /* exclude grunt files */
'!node_modules/**/*',
'!gruntfile.js',
'!package.json',
'!**/Web.config', /* exclude localized site config files */
'!**/global.asa'
],
dest: '//beckster/wwwroot/damien.mediabistro.net/'
}]
}
}
});
/* compass compilation */
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-newer');
// Default task(s).
grunt.registerTask('default', ['watch']);
};