javascriptcsssasscompass-sassuglifyjs

Add a comment with date or an incrementing "version" number to js, css or html files using a preprocessor?


I am working on a project for which the end client gets a lot of build.

Sometimes a fix is reported not repaired when it has been and it turns out the latest build has not been uploaded by they tech team. Our solution to this has been to comment by hand a date of release as we send it out, then we can check they upload and compare to our build.

We want to remove the risk of one of the team forgetting to version number a build, is it possible using a pre-processor to add one as a comment or even a JS var.

I know uglify.js has a 'define' parameter function, would this work, no one in the team has experience in this? We are also using compass to combine scss files.


Solution

  • Without knowing more about your build process it's difficult to give the best answer. (How are uglify and compass invoked?)

    Here is one method:

    (echo -n '// '; date; uglify input) > output
    

    This is a Linux command that prepends the output of the date command to the output of uglify (source). A similar batch file could be written for Windows environments. Or Grunt could be used for a cross-platform solution...


    Myself, I developed a system that automatically incorporates the Git version when building my project.