Skip to content

Commit 59bbd29

Browse files
committed
Update extension to load entrypoint build path.
1 parent 0f69516 commit 59bbd29

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/DependencyInjection/WebpackEncoreExtension.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
use Symfony\Component\DependencyInjection\ContainerBuilder;
1414
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1515
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
16+
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
17+
use Symfony\Component\DependencyInjection\Definition;
18+
use Symfony\Component\DependencyInjection\Reference;
19+
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookup;
1620

1721
final class WebpackEncoreExtension extends Extension
1822
{
@@ -24,7 +28,23 @@ public function load(array $configs, ContainerBuilder $container)
2428
$configuration = $this->getConfiguration($configs, $container);
2529
$config = $this->processConfiguration($configuration, $configs);
2630

31+
$factories = [
32+
'_default' => new Reference($this->entrypointFactory($container, '_default', $config['output_path']))
33+
];
34+
foreach ($config['builds'] as $name => $path) {
35+
$factories[$name] = new Reference($this->entrypointFactory($container, $name, $path));
36+
};
37+
2738
$container->getDefinition('webpack_encore.entrypoint_lookup')
28-
->replaceArgument(0, $config['output_path'].'/entrypoints.json');
39+
->replaceArgument(0, $factories['_default']);
40+
$container->getDefinition('webpack_encore.entrypoint_lookup_collection')
41+
->replaceArgument(0, ServiceLocatorTagPass::register($container, $factories));
42+
}
43+
44+
private function entrypointFactory(ContainerBuilder $container, string $name, string $path): string
45+
{
46+
$id = sprintf('webpack_encore.entrypoint_lookup[%s]', $name);
47+
$container->setDefinition($id, new Definition(EntrypointLookup::class, [$path.'/entrypoints.json']));
48+
return $id;
2949
}
3050
}

src/Resources/config/services.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
<service id="webpack_encore.entrypoint_lookup" class="Symfony\WebpackEncoreBundle\Asset\EntrypointLookup">
1111
<argument /> <!-- entrypoints.json path -->
1212
</service>
13+
<service id="webpack_encore.entrypoint_lookup_collection" class="Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection">
14+
<argument /> <!-- build list of entrypoints path -->
15+
</service>
1316

1417
<service id="webpack_encore.tag_renderer" class="Symfony\WebpackEncoreBundle\Asset\TagRenderer">
15-
<argument type="service" id="webpack_encore.entrypoint_lookup" />
18+
<argument type="service" id="webpack_encore.entrypoint_lookup_collection" />
1619
<argument type="service" id="assets.packages" />
1720
</service>
1821

@@ -23,6 +26,7 @@
2326
<tag name="container.service_locator" />
2427
<argument type="collection">
2528
<argument key="webpack_encore.entrypoint_lookup" type="service" id="webpack_encore.entrypoint_lookup" />
29+
<argument key="webpack_encore.entrypoint_lookup_collection" type="service" id="webpack_encore.entrypoint_lookup_collection" />
2630
<argument key="webpack_encore.tag_renderer" type="service" id="webpack_encore.tag_renderer" />
2731
</argument>
2832
</service>

0 commit comments

Comments
 (0)