Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails off assets pipeline

Rails off assets pipeline

Introduce why we should deprecate assets pipeline and how to integrate webpack with your current rails app.

JunChen Xia

October 14, 2015
Tweet

More Decks by JunChen Xia

Other Decks in Programming

Transcript

  1. Rails Asset Pipeline • Added in Rails 3.1 (2011) •

    Based on Sprockets (Assets joiner for Rack)
  2. Benefits • Introduce some FE good practices in BE world

    • Deliver a single Javascript file per page • CSS + JS minifying and image sprites • Promote compilers (less, coffee, sass…) • Very simple
  3. • Multiple clients, single API • Web is just ONE

    client • Front End is (very) complex
  4. NPM

  5. Webpack • Can do what asset pipeline does • Support

    modular JavaScript • Fully integrated with NPM • Even more …
  6. Migrating recipe • Put your new sources in a different

    spot • Setup npm and webpack • Move Javascript + Images • Move CSS + Images
  7. CommonJS • Each file is a module • A module

    need to explicitly declare what’s visible to other modules with “exports” • Others modules can access “exports” by using “require”
  8. CSS

  9. What else? • Minifying (with easy control) • Bundles grow

    super big • Optimisation and introspection tools • Easy split code tools • Semi-automatic common chunks • Bunch of loaders for (almost) any type of file
  10. Recap • Rails • Good for prototyping • Good to

    discover FE good practices • Doesn’t fit for large javascript applications • Looked production-ready in 2011 because server- side rendering technology is very limited • Front end world • Solves its own problems :)
  11. I didn’t talk about • Bower (enhanced dependencies management) •

    React (last FE revolution from Facebook) • ES2015 (coffeescript replacement) • Babel (ES2015 + Jsx compiler)