Install the package:
composer require armin/scssphp-bundle
Symfony Flex will auto-configure the bundle.
Define a basic SCSS asset in config/packages/scssphp.yaml:
scssphp:
enabled: true
assets:
"css/app.css":
src: "assets/scss/app.scss"
Reference the compiled CSS in Twig:
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
Verify in dev mode:
Edit SCSS files (assets/scss/*.scss) and save.
Auto-reload: The bundle recompiles changed files on request (no Node.js needed).
Debug: Use the Profiler Toolbar to inspect:
Configuration Overrides:
primary: '#0066cc').
scssphp:
assets:
"css/app.css":
variables:
$primary: "#0066cc"
importPaths:
- "vendor/twbs/bootstrap/scss"
Output Styles:
outputStyle: expanded for debugging, compressed for production.sourceMap: true for browser debugging (requires appendTimestamp: true).CLI Compilation:
php bin/console scssphp:compile
php bin/console scssphp:compile all -n
Caching Issues:
autoUpdate and use the CLI command to avoid runtime compilation:
scssphp:
enabled: true
autoUpdate: false # Disable auto-reload in prod
php bin/console cache:clear
Source Map Paths:
sourceMap: true, ensure the generated .map files are accessible via asset():
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<!-- Source map (if enabled) -->
<script src="{{ asset('css/app.css.map') }}"></script>
Variable Scope:
scssphp.yaml override defaults but do not merge with SCSS file variables.!default in SCSS files to preserve fallback values:
$primary: #ff0000 !default;
Symlink Conflicts:
outputFolder: public, ensure the target directory exists (e.g., mkdir -p public/css).Profiler Panel:
CLI Verbosity:
-v for detailed output:
php bin/console scssphp:compile -v
Environment-Specific Configs:
%kernel.environment% to toggle features:
scssphp:
enabled: "%env(bool:SCSSPHP_ENABLED)%"
Custom Formatters:
ScssPhp\ScssPhp\Formatter\FormatterInterface and inject via dependency injection.Pre/Post-Compile Hooks:
scssphp.compile event in a service:
use Symfony\Component\EventDispatcher\GenericEvent;
public function onScssCompile(GenericEvent $event) {
$asset = $event->getArgument('asset');
// Modify $asset['variables'] or $asset['src'] here
}
services.yaml:
services:
App\EventListener\ScssListener:
tags:
- { name: kernel.event_listener, event: scssphp.compile, method: onScssCompile }
Asset Discovery:
AssetLoader.
How can I help you explore Laravel packages today?