Skip to content

Instantly share code, notes, and snippets.

@aderowbotham
Last active May 11, 2020 10:11
Show Gist options
  • Save aderowbotham/af9ee034f816960670fa4fd218e6a8ec to your computer and use it in GitHub Desktop.
Save aderowbotham/af9ee034f816960670fa4fd218e6a8ec to your computer and use it in GitHub Desktop.
Set cache-busing file revision using Grunt
/*
Example using grunt-contrib-concat, but this should work with any package
Inject string-based timestamp into an output filename, e.g. vendor-min.ka2bct2u.js
*/
module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.initConfig({
revision: new Date().getTime().toString(36),
concat: {
options: {
separator: ";",
},
vendor: {
src: [
"node_modules/some-pkg/pgk.min.js",
"node_modules/some-pkg-extension/pgk-extension.min.js",
],
dest: "deploy/public/vendor/vendor-min.<%= revision %>.js",
}
}
});
grunt.registerTask("Compile", "Concatenate vendor libraries", function(){
grunt.task.run(["concat:vendor"]);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment