I'm trying to replace some placeholders in different files as I copy. My gruntfile works fine, but adding in the process option to do the replacements, it's just not working. Below is the relevant section of my gruntfile:
grunt.initConfig({
copy: {
js: {
files: [{
expand: true,
cwd: 'src/wp-content/themes/pilau-starter/',
src: ['**/*.js'],
dest: 'public/wp-content/themes/pilau-starter/'
}],
options: {
process: function ( content ) {
console.log( content );
content = content.replace( /pilauBreakpointLarge/g, breakpoints.large );
content = content.replace( /pilauBreakpointMedium/g, breakpoints.medium );
return content;
}
}
},
}
});
The paths can be understood in the context of the code on GitHub: https://github.com/pilau/starter (the public directory isn't committed to the repo because it's a starter theme). Those paths are variables in my original Gruntfile, and are working fine in all other tasks.
All the vars are set up OK. I've included the console.log( content )
to check if the process function's actually running - it doesn't seem to be, so I guess it's basic syntax.
There's an answer (https://mcmap.net/q/1916744/-using-regex-in-grunt-contrib-copy-39-s-quot-process-quot-option-not-working) which seems to address this, but as far as I can tell, that way of doing it is simply bad JS syntax - not sure how it got marked as right.
--verbose
output for running the copy task:
Running "copy:js" (copy) task
Verifying property copy.js exists in config...OK
Files: src/wp-content/themes/pilau-starter/js/admin.js -> public/wp-content/themes/pilau-starter/js/admin.js
Files: src/wp-content/themes/pilau-starter/js/flickity.js -> public/wp-content/themes/pilau-starter/js/flickity.js
Files: src/wp-content/themes/pilau-starter/js/global.js -> public/wp-content/themes/pilau-starter/js/global.js
Files: src/wp-content/themes/pilau-starter/js/modernizr.js -> public/wp-content/themes/pilau-starter/js/modernizr.js
Files: src/wp-content/themes/pilau-starter/js/picturefill.js -> public/wp-content/themes/pilau-starter/js/picturefill.js
Files: src/wp-content/themes/pilau-starter/js/respond.js -> public/wp-content/themes/pilau-starter/js/respond.js
Options: processContent=false, processContentExclude=[], process=undefined
Options: processContent=false, processContentExclude=[], process=undefined
Copying src/wp-content/themes/pilau-starter/js/admin.js -> public/wp-content/themes/pilau-starter/js/admin.js
Reading src/wp-content/themes/pilau-starter/js/admin.js...OK
Writing public/wp-content/themes/pilau-starter/js/admin.js...OK
--verbose
flag? Also, thenonull
option can be helpful when debugging. – Adsorbategrunt-contrib-copy
are you using? You can try to useprocessContent
instead ofprocess
because it was used in v0.4.1 and earlier. You can also try to console log yourbreakpoints.large
andbreakpoints.medium
maybe they are not correctly set in your config... – Trappings--verbose
suggestion. – BiquarterlysrcThemeDir
as if copy finds no file, process is not executed and you get no log, as you described. Where do you define the variables? – Bounty--verbose
output - I'm guessingprocess=undefined
is the issue? Everything else is working - my edits are copied from src/ to /public fine.breakpoints
is logging fine. – Canfield