node.js - Add a Timestamp to the End of Filenames with Grunt -


during grunt tasks, add unique string end of filenames. have tried grunt-contrib-copy , grunt-filerev. neither have been able need them to...

currently less files automatically compiled on 'save' in sublime text 3 (so not yet occur in grunt tasks). then, open terminal , run 'grunt', concatenates (combines) js files. after done, grunt should rename 'dist/css/main.css' , 'dist/js/main.js' "version" @ end of filename.

i have tried:

  • grunt-contrib-copy ('clean:expired' deletes concatenated js before grunt-contrib-copy' can rename file)
  • grunt-filerev ('this worked on css files reason, , inserted version number before '.css'. not sure why didn't work on js files.')

here's gruntfile.js

so, clear, not asking "code review" need know how can incorporate "rename" process when tasks complete, have 'dist/css/main.css12345 & dist/js/main.js12345' no 'dist/css/main.css' or 'dist/js/main.js' left in respective directories.

thanks in advance help!

update: after experimenting this, ended using grunt-contrib-rename , works great! beleieve same results can achieved via grunt-contrib-copy, in fact know same thing. either work. far support regex, not sure if both support it, may else worth looking before choosing 1 of these plugins :)

your rename:dist looks should want, need move clean:dist first task runs (so deletes things prior build rather current build). order of tasks defined array on last line:

grunt.registertask('default', ['jshint:dev', 'concat:dist', 'less:dist', 'csslint:dist', 'uglify:dist', 'cssmin:dist', 'clean:dist', 'rename:dist']); 

that said, i'm not sure why want behavior. more common thing insert hash of file filename before file extension.

the difference between hash , timestamp hash value same long file contents don't change - if change 1 file, compiled output file different , browsers need re-downloaded 1 file while using cached versions of every other file.

the difference between putting number before file extension , after extension lot of tools (like ide) have behavior changes based on extension.

for more standard goal, there tons of ways accomplish 1 of more common combine grunt-filerev grunt-usemin create named files , update html file(s) reference these new file names


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -