Skip to content

Commit 191a60c

Browse files
committed
Allow disabling default build if multiple entry points are defined
1 parent ae7526c commit 191a60c

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ file:
2222
webpack_encore:
2323
# The path where Encore is building the assets - i.e. Encore.setOutputPath()
2424
output_path: '%kernel.public_dir%/build'
25+
# If multiple builds are defined (as shown below), you can disable the default build:
26+
# output_path: false
2527

2628
# if you have multiple builds:
2729
# builds:

src/DependencyInjection/Configuration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public function getConfigTreeBuilder()
2323
$rootNode = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('webpack_encore');
2424

2525
$rootNode
26+
->validate()
27+
->ifTrue(function (array $v): bool {
28+
return false === $v['output_path'] && empty($v['builds']);
29+
})
30+
->thenInvalid('Default build can only be disabled if multiple entry points are defined.')
31+
->end()
2632
->children()
2733
->scalarNode('output_path')
2834
->isRequired()

src/DependencyInjection/WebpackEncoreExtension.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ public function load(array $configs, ContainerBuilder $container)
2828
$configuration = $this->getConfiguration($configs, $container);
2929
$config = $this->processConfiguration($configuration, $configs);
3030

31-
$factories = [
32-
'_default' => new Reference($this->entrypointFactory($container, '_default', $config['output_path']))
33-
];
31+
$factories = [];
32+
33+
if ($config['output_path'] !== false) {
34+
$factories['_default'] = new Reference($this->entrypointFactory($container, '_default', $config['output_path']));
35+
}
36+
3437
foreach ($config['builds'] as $name => $path) {
3538
$factories[$name] = new Reference($this->entrypointFactory($container, $name, $path));
36-
};
39+
}
3740

38-
$container->getDefinition('webpack_encore.entrypoint_lookup')
39-
->replaceArgument(0, $factories['_default']);
4041
$container->getDefinition('webpack_encore.entrypoint_lookup_collection')
4142
->replaceArgument(0, ServiceLocatorTagPass::register($container, $factories));
4243
}

src/Resources/config/services.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<services>
88
<defaults public="false" />
99

10-
<service id="webpack_encore.entrypoint_lookup" class="Symfony\WebpackEncoreBundle\Asset\EntrypointLookup">
11-
<argument /> <!-- entrypoints.json path -->
12-
</service>
1310
<service id="webpack_encore.entrypoint_lookup_collection" class="Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection">
1411
<argument /> <!-- build list of entrypoints path -->
1512
</service>
@@ -25,7 +22,6 @@
2522
<service class="Symfony\Component\DependencyInjection\ServiceLocator">
2623
<tag name="container.service_locator" />
2724
<argument type="collection">
28-
<argument key="webpack_encore.entrypoint_lookup" type="service" id="webpack_encore.entrypoint_lookup" />
2925
<argument key="webpack_encore.entrypoint_lookup_collection" type="service" id="webpack_encore.entrypoint_lookup_collection" />
3026
<argument key="webpack_encore.tag_renderer" type="service" id="webpack_encore.tag_renderer" />
3127
</argument>

0 commit comments

Comments
 (0)