SymfonyCasts Sass Bundle
Delightful Sass support for Symfony AssetMapper with no Node.js required
Repository Health
Technical Analysis
The SymfonyCasts Sass Bundle adds first-class Sass/SCSS support to Symfony’s AssetMapper component without requiring Node.js. It automatically downloads the correct standalone Dart Sass binary for your platform and compiles your Sass files into CSS that AssetMapper then serves with versioned filenames.
The bundle registers a sass:build console command to compile and watch your stylesheets, and hooks into AssetMapper’s compile lifecycle so your Sass is built automatically during asset compilation and deployment. It lets Symfony developers write Sass in a modern, build-free frontend workflow.
What You Get
- Automatic download of the correct standalone Dart Sass binary (no Node.js)
- A
sass:buildconsole command with build and watch modes - Integration with Symfony AssetMapper so compiled CSS is served with versioned filenames
- Automatic Sass compilation during asset compilation and deployment
- Configurable Sass entrypoints and options through bundle configuration
Common Use Cases
- Writing SCSS in a Symfony app that uses AssetMapper instead of a Node.js build toolchain
- Watching and rebuilding Sass automatically during local development
- Compiling Sass to versioned CSS as part of a production asset build
- Adopting Sass in a build-free Symfony frontend without installing npm dependencies
Under The Hood
Architecture - The bundle is a thin, well-factored wrapper around Dart Sass. SassBinary (src/SassBinary.php) locates and downloads the platform-specific binary via symfony/http-client, and SassBuilder (src/SassBuilder.php) invokes it through symfony/process to compile entrypoints. A SassBuildCommand (src/Command) exposes build/watch, while AssetMapper/SassCssCompiler and a PreAssetsCompileEventListener (src/Listener) hook the compilation into AssetMapper’s lifecycle so CSS is produced before assets are digested.
Tech Stack - PHP (>=8.1) packaged as a Symfony bundle with PSR-4 autoloading under Symfonycasts\SassBundle. It depends on symfony/asset-mapper, console, filesystem, http-client, process, and finder (^5.4 through ^8.0). The actual Sass compilation is delegated to the standalone Dart Sass executable.
Code Quality - The source is small and focused, split cleanly into binary management, building, command, and AssetMapper integration. It is covered by a PHPUnit suite under tests/ and checked with PHPStan and php-cs-fixer via dedicated tools/ setups.
API Design - Setup is nearly zero-config: install the bundle, point it at a Sass entrypoint, and run sass:build (or let AssetMapper trigger it). By removing the Node.js/npm requirement entirely, it makes adopting Sass in Symfony dramatically simpler than a traditional bundler pipeline.