Skip to content

Commit dbdaaaa

Browse files
committed
Allow disabling default build if multiple entry points are defined
1 parent e23e9d3 commit dbdaaaa

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
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.project_dir%/public/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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ public function load(array $configs, ContainerBuilder $container)
3030
$configuration = $this->getConfiguration($configs, $container);
3131
$config = $this->processConfiguration($configuration, $configs);
3232

33-
$factories = [
34-
'_default' => $this->entrypointFactory($container, '_default', $config['output_path'], $config['cache']),
35-
];
36-
$cacheKeys = [
37-
'_default' => $config['output_path'].'/'.self::ENTRYPOINTS_FILE_NAME,
38-
];
33+
$factories = [];
34+
$cacheKeys = [];
35+
36+
if (false !== $config['output_path']) {
37+
$factories['_default'] = $this->entrypointFactory($container, '_default', $config['output_path'], $config['cache']);
38+
$cacheKeys['_default'] = $config['output_path'].'/'.self::ENTRYPOINTS_FILE_NAME;
39+
}
40+
3941
foreach ($config['builds'] as $name => $path) {
4042
$factories[$name] = $this->entrypointFactory($container, $name, $path, $config['cache']);
4143
$cacheKeys[rawurlencode($name)] = $path.'/'.self::ENTRYPOINTS_FILE_NAME;

0 commit comments

Comments
 (0)