Reputation: 1020
I`m using grunt-string-replace to add the pkg.version value (defined in grunt.initConfig) to a css file name, to avoid caching when version changed. I also added a function in order to remove the dots from the version string. The result filename looks like this: style.css?013
Can i use the initConfig pkg.version value inside my replacement function instead of reading it again from the package file?
This is my string-replace configuration:
"string-replace": {
dist: {
files: {
"dist/test.html": "dist/test.html"
},
options: {
replacements: [{
pattern: '#pkgversion#',
replacement: function(){var p=grunt.file.readJSON('package.json'); return p.version.replace(/\./g ,'');},
}]
}
},
},
Upvotes: 0
Views: 505
Reputation: 9650
Use the grunt.config.get method.
For example:
replacement: function(){
return grunt.config.get('pkg').version.replace(/\./g ,'');
}
Upvotes: 1