diff --git a/config/services.php b/config/services.php index e46091e..e54490f 100644 --- a/config/services.php +++ b/config/services.php @@ -17,6 +17,7 @@ abstract_arg('path to css directory'), param('kernel.project_dir'), abstract_arg('path to binary'), + abstract_arg('embed sourcemap'), ]) ->set('sass.command.build', SassBuildCommand::class) diff --git a/src/DependencyInjection/SymfonycastsSassExtension.php b/src/DependencyInjection/SymfonycastsSassExtension.php index faa8c00..360b791 100644 --- a/src/DependencyInjection/SymfonycastsSassExtension.php +++ b/src/DependencyInjection/SymfonycastsSassExtension.php @@ -19,8 +19,12 @@ class SymfonycastsSassExtension extends Extension implements ConfigurationInterface { + private bool $isDebug; + public function load(array $configs, ContainerBuilder $container): void { + $this->isDebug = $container->getParameter('kernel.debug'); + $loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../../config')); $loader->load('services.php'); @@ -31,6 +35,7 @@ public function load(array $configs, ContainerBuilder $container): void ->replaceArgument(0, $config['root_sass']) ->replaceArgument(1, '%kernel.project_dir%/var/sass') ->replaceArgument(3, $config['binary']) + ->replaceArgument(4, $config['embed_sourcemap']) ; $container->findDefinition('sass.css_asset_compiler') @@ -64,6 +69,10 @@ public function getConfigTreeBuilder(): TreeBuilder ->info('The Sass binary to use') ->defaultNull() ->end() + ->scalarNode('embed_sourcemap') + ->info('Whether to embed the sourcemap in the compiled CSS. By default, enabled only when debug mode is on.') + ->defaultValue($this->isDebug) + ->end() ->end() ; diff --git a/src/SassBuilder.php b/src/SassBuilder.php index 444bb34..c200a9c 100644 --- a/src/SassBuilder.php +++ b/src/SassBuilder.php @@ -24,7 +24,8 @@ public function __construct( private readonly array $sassPaths, private readonly string $cssPath, private readonly string $projectRootDir, - private readonly ?string $binaryPath + private readonly ?string $binaryPath, + private readonly bool $embedSourcemap, ) { } @@ -38,6 +39,10 @@ public function runBuild(bool $watch): Process $args[] = '--watch'; } + if ($this->embedSourcemap) { + $args[] = '--embed-source-map'; + } + $process = $binary->createProcess($args); if ($watch) { diff --git a/tests/SassBuilderTest.php b/tests/SassBuilderTest.php index 3f891a4..a651d96 100644 --- a/tests/SassBuilderTest.php +++ b/tests/SassBuilderTest.php @@ -27,6 +27,7 @@ public function testIntegration(): void __DIR__.'/fixtures/assets', __DIR__.'/fixtures', null, + false ); $process = $builder->runBuild(false);