plugins - Gruntjs: How to make copy task to copy only changed files on watch -
so on grunt-contrib-watch plugin info page, there example on how make jshint run changed file.
grunt.initconfig({ watch: { scripts: { files: ['lib/*.js'], tasks: ['jshint'], options: { nospawn: true, }, }, }, jshint: { all: ['lib/*.js'], }, }); grunt.event.on('watch', function(action, filepath) { grunt.config(['jshint', 'all'], filepath); });
i have not tested example self. took , applied copy task, unsuccessfully. grunt-contrib-copy task set copy images , templates angular project. , happy know if can make work copy task , if can, doing wrong.
thank much.
here stripped out gruntfile.js.
// build configurations. module.exports = function(grunt){ // project configuration. grunt.initconfig({ pkg: grunt.file.readjson('package.json'), // copies directories , files 1 location another. copy: { // development devtmpl: { files: [{ cwd : 'src/tpl/', src : ['**/*'], dest : 'app/tpl/', flatten : false, expand : true }] }, devimg: { files: [{ cwd : 'src/img/', src : ['**/*'], dest : 'app/img/', flatten : false, expand : true }] } }, // watch files changes , run tasks watch: { // templates, copy templates: { files : 'src/tpl/**/*', tasks : ['copy:devtmpl'], options: { nospawn: true, } }, // images, copy images: { files : 'src/img/**/*', tasks : ['copy:devimg'], options: { nospawn: true, } } } }); // watch events grunt.event.on('watch', function(action, filepath) { // configure copy:devtmpl run on changed file grunt.config(['copy','devtmpl'], filepath); // configure copy:devimg run on changed file grunt.config(['copy','devimg'], filepath); }); // plugins: grunt.loadnpmtasks('grunt-contrib-copy'); // tasks: /* dev: compiles app non-optimized build settings, places build artifacts in dist directory, , watches file changes. run: grunt dev */ grunt.registertask('dev', 'running "development", watching files , compiling...', [ 'default', 'watch' ]); /* default: compiles app non-optimized build settings , places build artifacts in dist directory. run: grunt */ grunt.registertask('default', 'running "default", compiling everything.', [ 'copy:devtmpl', 'copy:devimg' ]); }
use grunt-sync (https://npmjs.org/package/grunt-sync) instead of grunt-contrib-copy, , watch directories want synced.
update - here's example:
grunt.initconfig({ sync: { copy_resources_to_www: { files: [ { cwd: 'src', src: 'img/**', dest: 'www' }, { cwd: 'src', src: 'res/**', dest: 'www' } ] } } });
cwd means current working directory. copy_resources_to_www label.
Comments
Post a Comment