How CSS Bundling for Rails works
mainThis gem uses a Node-based bundler to process stylesheets and delivers the output via the Rails asset pipeline.
Development Workflow
- Watch Mode: Run
yarn build:css --watchin a terminal to automatically recompile CSS when files change. - Unified Dev Command: Use
./bin/devto start both the Rails server and the CSS build watcher (and JS watcher if usingjsbundling-rails). - Output Convention: The bundler takes an entrypoint at
app/assets/stylesheets/application.[bundler].cssand outputs the result toapp/assets/builds/application.css. This directory is added to.gitignoreby default. - Asset Linking: In your layouts, continue using the standard asset pipeline helper:
<%= stylesheet_link_tag "application" %>
Production and Testing
- Production: The
css:buildtask is attached toassets:precompile. It ensuresyarndependencies are installed and runsyarn build:cssbefore the asset pipeline digests and copies the files topublic/assets. - Testing: The
css:buildtask is attached totest:prepare. If your test framework does not calltest:prepare, you must manually runcss:build(andjavascript:buildif usingjsbundling-rails) before running tests.