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

Js-bundling, css-bundling and propshaft

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Js-bundling, css-bundling and propshaft

Slides from my talk at RoroSyd June 2022.

The demoonstration code is available at https://github.com/langsharpe/rails_bundling_example

Avatar for Lang Sharpe

Lang Sharpe

June 28, 2022

Other Decks in Programming

Transcript

  1. One of four options • Sprockets • Webpacker • Import

    maps • Bundling gems (this one) See "Guide to Rails 7 and the Asset Pipeline" by Breno Gazzola
  2. Let's say your application contains... • Plain ES6 Javascript •

    Typescript • jQuery • Postcss plugins, like Autopre fi xer • Sass • Tailwind
  3. ... you can create a solution from • Jsbundling-rails gem

    • Cssbundling-rails gem • Propshaft gem • Esbuild • Postcss • Sass, Tailwind etc.
  4. A new convention for assets • Two new processes to

    bundle js and css • Two scripts in package.json web: bin/rails server -p 3000 js: yarn build --watch css: yarn build:css --watch "scripts": { "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds", "build:css": "postcss --verbose ./app/assets/stylesheets/application.postcss.css -o ./ app/assets/builds/application.css" }
  5. A new convention for assets • Bundlers read from /app/assets/stylesheets

    and /app/javascript • They output to /app/assets/builds • Nothing is happening with ruby or rails (yet) "scripts": { "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds", "build:css": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./ app/assets/builds/application.css --minify" }
  6. Benefits - Simplicity • Propshaft 633 lines of code •

    Jsbundling is 131 lines of code • Css bundling is 163 lines of code • Webpacker is 1363 lines of ruby + 1485 lines of js
  7. Benefits - Separation • Separation of concerns • Clear place

    where ruby ends and js starts • JS and CSS pipelines are separate • Supported options other than webpack • Esbuild is a very fast JS bundler
  8. Tradeoffs • Feature test support • No speci fi c

    support, remember to run manually • Propshaft has not reached v1.0.0 • It's used in production by Basecamp and others • You could replace it with sprockets • Documentation is lacking, maybe avoid if you are a beginner