Skip to content

Instantly share code, notes, and snippets.

@bittersweetryan
Last active December 22, 2015 18:49
Show Gist options
  • Save bittersweetryan/6515680 to your computer and use it in GitHub Desktop.
Save bittersweetryan/6515680 to your computer and use it in GitHub Desktop.
This Grunt config will only run a task on the file that has triggered the watch plugin.
/*
automatically sync files from the deploy directory back to the source directory
*/
module.exports = function( grunt ){
grunt.initConfig( {
copy : {
main: {
files : [
]
}
},
watch : {
js : {
files : [
getDirForType( 'js', 'web' )
],
tasks : [
'copy'
],
options : {
spawn : false
}
}
}
} );
grunt.event.on( 'watch', function( action, filepath, taskName ){
var files = grunt.config( 'copy.main.files' ),
fileName = new RegExp('/' + taskName + '.+').exec( filepath )[0];
files.push(
{
src : filepath,
dest : deployDir + fileName
}
);
grunt.config( 'copy.main.files', files );
} );
require( 'matchdep' ).filterDev( 'grunt-*' ).forEach( grunt.loadNpmTasks );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment