In a Rails 8.1 app, when would you pick dartsass-rails, tailwindcss-rails or cssbundling-rails, and what does each need at build time?
answer
- standalone binaries: no Node for two of them
- dartsass: application.scss to application.css
- tailwindcss-rails 4: app/assets/tailwind/application.css
- cssbundling: package.json build:css
- pick by whether Node is already there
basics
~20 sdartsass-rails and tailwindcss-rails run standalone binaries shipped as gems, so they need no Node; cssbundling-rails runs a package.json build:css script through Node or Bun and supports Sass, Tailwind, PostCSS, Bootstrap and Bulma. Choose by whether the app already has a JavaScript toolchain.
solid answer
~40 sAll three write into `app/assets/builds` for Propshaft. **dartsass-rails** wraps the Dart Sass executable from the `sass-embedded` gem: it compiles `config.dartsass.builds` (default `{ "application.scss" => "application.css" }`) from `app/assets/stylesheets` with `--style=compressed --no-source-map`, no Node required. **tailwindcss-rails 4** runs the Tailwind v4 standalone CLI from `tailwindcss-ruby`, reading `app/assets/tailwind/application.css` (which it excludes from Propshaft) and writing a minified `builds/tailwind.css`; there is no `tailwind.config.js`, configuration lives in the CSS. **cssbundling-rails** needs Node or Bun and runs `build:css` from `package.json`, with installers for tailwind, postcss, sass, bootstrap and bulma. `rails new -c sass` or `-c tailwind` without a JavaScript bundler gets the standalone gem; with one, cssbundling-rails. The property-management team adding TypeScript will have Node anyway, which tips a Sass theme toward cssbundling-rails, though dartsass-rails keeps CSS builds Node-free.
code
ruby · 5 lines# config/initializers/dartsass.rb
Rails.application.config.dartsass.builds = {
"application.scss" => "application.css",
"admin/owners.scss" => "owners.css"
}go deeper
Recall that dartsass-rails and tailwindcss-rails need no Node, while cssbundling-rails runs a package.json script.
Explain each gem's input, output and build-time dependency, and the tailwindcss-rails 4 change to CSS-based configuration.
Choose for a real app: reuse an existing Node toolchain or keep CSS Node-free, and spot load-path and output-name pitfalls.
Set a team policy on front-end toolchains: how many runtimes the build may depend on, and the cost of each in CI and images.
## The shared contract Every CSS build gem in Rails 8.1 does the same three things: compile a source stylesheet, write the result into **`app/assets/builds`**, and hook its build into `assets:precompile`, `test:prepare` and a `bin/dev` watcher. Propshaft then serves the output. What differs is **what has to be installed to run the compiler** and where the source lives. ## dartsass-rails - **Compiler:** the Dart Sass executable shipped by the `sass-embedded` gem (dartsass-rails depends on `sass-embedded ~> 1.63`). No Node, no `package.json`. - **Input and output:** `config.dartsass.builds` maps files under `app/assets/stylesheets` to files in `app/assets/builds`. The default is `{ "application.scss" => "application.css" }`; add entries for an admin theme or a print stylesheet. - **Options:** `config.dartsass.build_options` defaults to `["--style=compressed", "--no-source-map"]`. - **Load paths:** `app/assets/stylesheets` plus every entry in `config.assets.paths` is passed as `--load-path`, so `@use` can reach styles shipped in gem asset folders. - **Tasks:** `dartsass:build`, `dartsass:watch`, and `dartsass:clobber` hooked into `assets:clobber`. ## tailwindcss-rails 4 - **Compiler:** the Tailwind CSS v4 standalone CLI from `tailwindcss-ruby` (`~> 4.0`). No Node for the build itself. - **Input and output:** `app/assets/tailwind/application.css` (which starts as `@import "tailwindcss";`) compiles to `app/assets/builds/tailwind.css`, minified unless built with `tailwindcss:build[debug]` or `TAILWINDCSS_DEBUG`. - **Propshaft:** the gem adds `app/assets/tailwind` to `config.assets.excluded_paths`, so the raw input never reaches `public/assets`. - **Configuration:** since 4.0 there is no `config/tailwind.config.js`; Tailwind v4 is configured in the CSS file. A v3 app upgrades with `bin/rails tailwindcss:upgrade`, which runs the upstream upgrader through `npx` once. - **Extras:** a Puma plugin to run the watcher inside `bin/rails server`. ## cssbundling-rails - **Compiler:** whatever `package.json` names, run as `yarn build:css` (or the bun, pnpm or npm equivalent). Node or Bun is required in development, CI and the build image. - **Installers:** `bin/rails css:install:tailwind`, `:postcss`, `:sass`, `:bootstrap` and `:bulma`. The Sass installer writes `app/assets/stylesheets/application.sass.scss` and a `build:css` script compiling it to `app/assets/builds/application.css` with `--load-path=node_modules`. - **Strength:** npm packages such as Bootstrap's Sass sources resolve from `node_modules`, and PostCSS plugins are available. ## Choosing | Situation | Good fit | Why | |---|---|---| | Import maps, no Node anywhere, Sass theme | dartsass-rails | keeps the whole app Node-free | | Import maps, utility-first CSS | tailwindcss-rails | standalone binary, Puma plugin | | jsbundling-rails already present | cssbundling-rails | one `package.json`, one toolchain | | Theme built on npm Sass packages | cssbundling-rails | resolves from `node_modules` | `rails new` encodes the first two rows: `-c tailwind` or `-c sass` with import maps installs tailwindcss-rails or dartsass-rails, while any JavaScript bundler, or another `-c` value, gets cssbundling-rails. ## The property-management decision The team wants TypeScript, so jsbundling-rails brings Node, Yarn and a `package.json` into development, CI and the Docker image regardless of the CSS choice. Given that: 1. **cssbundling-rails with Sass** reuses the toolchain, lets the theme `@use` npm packages and keeps all front-end dependencies in one lockfile. 2. **dartsass-rails** still works and keeps CSS builds independent of Node, which matters if the team might later drop the bundler. Either is defensible; the interview signal is naming the build-time dependency each one adds rather than picking by habit. ## Pitfalls - With dartsass-rails, Sass partials in `app/assets/stylesheets` stay on Propshaft's load path and get copied to `public/assets` unless that folder is excluded. - Running cssbundling-rails and jsbundling-rails together can produce two `application.css` files in `builds` if JavaScript imports CSS; give one output another name. - Do not follow v3-era Tailwind guides that edit `config/tailwind.config.js` or `application.tailwind.css` in a tailwindcss-rails 4 app. ## How each fits into development and deploys | Gem | Watch process in `Procfile.dev` | Precompile hook | Skip with | |---|---|---|---| | dartsass-rails | `css: bin/rails dartsass:watch` | `dartsass:build` | `SKIP_CSS_BUILD` | | tailwindcss-rails | `css: bin/rails tailwindcss:watch` (or the Puma plugin) | `tailwindcss:build` | not skippable | | cssbundling-rails | `css: yarn build:css --watch` | `css:build` after `css:install` | `SKIP_CSS_BUILD` | The standalone gems also make the production image smaller and simpler when nothing else needs Node: their build tasks run Ruby that execs a platform binary already installed with the bundle. The trade-off is reach: npm-only Sass libraries or PostCSS plugins are a reason to accept the Node dependency that cssbundling-rails brings.
- Where does Tailwind configuration go in a tailwindcss-rails 4 app?In the CSS input, `app/assets/tailwind/application.css`, which starts with `@import "tailwindcss";`. tailwindcss-rails 4 no longer creates `config/tailwind.config.js`, and `postcss.config.js`, if used, sits at the app root. `bin/rails tailwindcss:upgrade` migrates a v3 app.
- How does dartsass-rails let a theme @use styles from a gem?Its runner passes `app/assets/stylesheets` and every directory in `config.assets.paths` as `--load-path` arguments to Dart Sass. A gem that exposes `app/assets/stylesheets` through its engine is therefore on the Sass load path with no extra configuration.
- dartsass-rails needs Node because Sass is an npm package
- tailwindcss-rails 4 is configured in config/tailwind.config.js
- cssbundling-rails compiles Sass inside Propshaft
- rails new -c sass always installs cssbundling-rails
- Only cssbundling-rails hooks into assets:precompile
Assumes Rails 8.1 with dartsass-rails 0.5, tailwindcss-rails 4.6 and cssbundling-rails 1.4; tailwindcss-rails 4.0 moved the input to app/assets/tailwind/application.css and dropped config/tailwind.config.js.