Skip to content

Commit

Permalink
Adding embedded sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Aug 21, 2023
1 parent 6c733b5 commit f75d41d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/DependencyInjection/SymfonycastsSassExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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')
Expand Down Expand Up @@ -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()
;

Expand Down
7 changes: 6 additions & 1 deletion src/SassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/SassBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testIntegration(): void
__DIR__.'/fixtures/assets',
__DIR__.'/fixtures',
null,
false
);

$process = $builder->runBuild(false);
Expand Down

0 comments on commit f75d41d

Please sign in to comment.