1
votes

I am reading the guide on this site: http://blog.carbonfive.com/2014/05/05/roll-your-own-asset-pipeline-with-gulp/

and I read the following part:

Rev This is my favorite part of using Gulp. Rev will give you that friendly app-ef62e7.js filename output that Asset Pipeline is famous for. The reason for it is you can cache it forever. New requests will just point to new files. CDNs love this. To get the files to have the hash is pretty easy with Rev.

var rev = require('gulp-rev');

gulp.task('rev', ['less', 'scripts'], function() { return gulp.src(['dist//.css', 'dist//.js']) .pipe(rev()) .pipe(gulp.dest('dist')) .pipe(rev.manifest()) .pipe(gulp.dest('dist')); }); view rawgulpfile.js hosted with ❤ by GitHub Now the filename has the hash appended to it! Note the digest I generate as well; that looks like the following:

{ "app.css": "app-1c1d3237.css", "app.js": "app-26ad0c3f.js" } view rawrev-manifest.json hosted with ❤ by GitHub Here is where a bit of custom code would come into play. When you generate your index.html (or wherever else you reference the CSS/JS) you will have to swap out the URL for the one in the digest file. Should only be a matter of parsing this JSON file in your framework of choice, or having Gulp rewrite your index.html to replace the CSS/JS include with the correct filename.

This is all well and good and sounds fine to me but if I do that and Gulp injects the new filenames for my main css and js files then my git version control system is going to pick up this as a change EVERY SINGLE TIME I update my assets.

How do people deal with this?

1

1 Answers

0
votes

I use .gitignore and ignore the assets directory (/public/assets)

https://git-scm.com/docs/gitignore

Updated:

Rails will take care of the filenames for you. If you use the below helpers

<%= javascript_include_tag "application" %> <%= stylesheet_link_tag "application" %>

rails will read the manifest file and insert the correct file name when those helpers are executed.

Rails doing it's md5 thing: http://guides.rubyonrails.org/asset_pipeline.html#in-production

Manifest file: Read 4.1 of http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives Search for: manifest-md5hash.json

See source code: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-javascript_include_tag

I wrote my own asset application helper:

 def javascript_file(filename)
    files = Dir.glob(Rails.root.join('public/assets/manifest*.json'.freeze))
    if files.count > 0
      manifest = JSON.parse(File.read(files[0]))
      manifest[filename]
    else
      filename
    end   
  end