Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding embedded sourcemaps #7

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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