Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sails.js Asset Versioning

I'm using the sails.js asset linker.

I'm versioning my assets by appending an asset version in it like so:

assetfile.js?=<%= assetVersion %>

Unfortunately, this doesn't work because the js file names are being replaced by the linker!

Does the sails.js linker support a work around for this? Or am I left on my own to hack the grunt file?

like image 927
Secret Avatar asked May 29 '14 05:05

Secret


2 Answers

If you are hosting from a git repository, you can use the git commit sha to identify version.

I use this approach in one of my projects, and it consists of adding the following as rename.js to tasks/config

var git = require('git-rev')

module.exports = function(grunt) {

  git.short(function(hash) {

    var files = {
      '.tmp/public/min/production.' + hash + '.min.js': '.tmp/public/min/production.min.js',
      '.tmp/public/min/production.' + hash + '.min.css': '.tmp/public/min/production.min.css'
    }

    grunt.config.set('rename', {
      dist: {
        files: files
      }
    })

  })

  grunt.loadNpmTasks('grunt-rename')

};

and then adding the rename task in tasks/register/prod.js just before the linker tasks.

like image 57
caseyWebb Avatar answered Nov 16 '22 15:11

caseyWebb


Based on @CaseyWebb's solution we extended our sails app to address versioning issue with timestamp. There's also a very detailed blog entry about this here: https://naya.com.np/post/391862c0520b5b5632e99e812749a85b

like image 5
pewpewlasers Avatar answered Nov 16 '22 17:11

pewpewlasers