Skip to content

Instantly share code, notes, and snippets.

@mfyz
Created April 29, 2019 02:47
Show Gist options
  • Save mfyz/2e37fe66a66b2e012bcb597d938aaf58 to your computer and use it in GitHub Desktop.
Save mfyz/2e37fe66a66b2e012bcb597d938aaf58 to your computer and use it in GitHub Desktop.
Grunt Replace Example
module.exports = function (grunt) {
// measures the time each task takes
require('time-grunt')(grunt);
grunt.loadNpmTasks('grunt-replace');
grunt.initConfig({
// Store your Package file so you can reference its specific data whenever necessary
pkg: grunt.file.readJSON('package.json'),
replace: {
asset_version: {
options: {
// usePrefix: false,
patterns: [
{
match: /define\('CSS_VERSION\', '([0-9]*)'\)/,
replacement: function(){
return "define('CSS_VERSION', '" + (parseInt(arguments[1]) + 1) + "')";
}
},
{
match: /define\('JS_VERSION\', '([0-9]*)'\)/,
replacement: function(){
return "define('JS_VERSION', '" + (parseInt(arguments[1]) + 1) + "')";
}
}
]
},
files: [
{ expand: true, flatten: true, src: ['config.php'], dest: './' }
]
}
}
});
grunt.registerTask('default', ['replace']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment