vigetlabs / gulp-rails-pipeline

Ditch the Rails Asset Pipeline and roll your own with Gulp
MIT License
646 stars 64 forks source link

Not manifesting/versioning CSS & JS #33

Open mvarrieur opened 9 years ago

mvarrieur commented 9 years ago

Not sure if this is intentional or not, but I'm adapting this to my project and realized since the font versioning fix this (this commit: https://github.com/vigetlabs/gulp-rails-pipeline/commit/bf106ea4abe9134bc4e719c7dd2ace90545abd25#diff-e88ef86846aa4dbfb9831f43405256fd) seems to be excluding CSS and JS files because of this line:

https://github.com/vigetlabs/gulp-rails-pipeline/blob/master/gulp/tasks/rev/rev-assets.js#L7

I can't get this project to run locally so I can't test for sure, but it seems unintentional to me.

greypants commented 9 years ago

Good question.

That's actually intentional... or at least it was at one point. Originally, I was recommending including the generated css and js files into app/assets/{javascripts,stylesheets}/application.{css,js}, in which case, Rails would take care of revisioning the files.

In the original version of this based on gulp-starter. I'm revisioning in multiple steps.

1) First, hit all the assets, so their filenames change first. 2) Then replace the changed filenames in css and js files. 3) Now we can revision the css and js files. If any child asset filenames have changed, the css and js file will have changed too, which will change the newly generated hash.

If we versioned everything at the same time, the hash of the css and js files wouldn't change as a result of referenced assets changing, and you could have cached files being served pointing to old filenames.

But I guess I stripped out those later steps and decided to let Rails handle that bit. Not sure if I still agree with that decision or not, but that's the state of things.

At some point, I need to get this up to date with gulp-starter

davidham commented 9 years ago

@greypants thanks for the response. I'm using gulp-rails-pipeline for my app but I'm not using browserify--I'm still doing AMD modules. My rev-manifest.json has a font file, my one graphic file, a CSS sourcemap, and a js file named bind.polyfill.js, which I guess gets past your pattern in the commit referenced above. Was your intention to have your gulp pipeline create the global.js bundle and the Sass-ified CSS file, and then have the developer =require them in application.js and application.css? So if I were to build my JS file on the gulp side and then require it from the Rails side, the revving should work? Thanks for any advice you can offer--I love the project and your Viget blog, which has helped me a number of times.

greypants commented 9 years ago

@davidham yep, that's the gist of it. Rails's rake assets:precompile command will still rev and compress anything in the pipeline. So like you said, if you =require the files into the pipeline, you can use the rails revisioned files (that include your gulp-processed files) instead.

davidham commented 9 years ago

@greypants Would your new webpack tasks from gulp-starter-2 work in gulp-rails-pipeline, like in place of browserify/watchify? I had been thinking of getting started with webpack because I can still use my AMD files. Thanks again!

greypants commented 9 years ago

The file and configuration structure has changed quite a bit, so just doing a drop in replacement might require some figuring out, but yeah, that could work. I'll try to get this thing up to date in the next week, once I get gulp-starter 2.0 merged into master... which will be this week!

davidham commented 8 years ago

Sounds awesome! I got gulp-starter-2 working with my Rails app, seems like it's pretty straightforward and mostly driven by the path settings in the config file. Nice work!

greypants commented 8 years ago

@davidham yesssssss! That is music to my ears. So good to hear.