1

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 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

7 Comments

I do that already for assets but that wasn't what my question was about. My question is about the layout views.
I'm confused, your message seems to imply that you are re-writing your original asset files. All of the files output by gulp should be written to /public/assets or some such, and the original files should be left as is.
That task above allows the script and link tags linking to app.css and app.js to be updated in their view layout files everytime the compiled assets are updated. This then would have the effect of the VCS seeing a change on every update of some sort of asset.
Updated answer; in light of clarification
Thanks for the updated answer. I am not referring to the Rails Asset Pipeline. I am building my own asset system using Gulp and this is in reference to that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.