Skip to content

Commit 614964e

Browse files
committed
Add cache flag
1 parent 465aae2 commit 614964e

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function getConfigTreeBuilder()
2828
->isRequired()
2929
->info('The path where Encore is building the assets - i.e. Encore.setOutputPath()')
3030
->end()
31+
->booleanNode('cache')
32+
->info('Enable caching of the entry point file(s)')
33+
->defaultFalse()
34+
->end()
3135
->arrayNode('builds')
3236
->useAttributeAsKey('name')
3337
->scalarPrototype()

src/DependencyInjection/WebpackEncoreExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
namespace Symfony\WebpackEncoreBundle\DependencyInjection;
1111

1212
use Symfony\Component\Config\FileLocator;
13-
use Symfony\Component\DependencyInjection\ContainerBuilder;
14-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
15-
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1613
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1715
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1817
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1919
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookup;
2020

2121
final class WebpackEncoreExtension extends Extension
@@ -29,13 +29,13 @@ public function load(array $configs, ContainerBuilder $container)
2929
$config = $this->processConfiguration($configuration, $configs);
3030

3131
$factories = [
32-
'_default' => $this->entrypointFactory($container, '_default', $config['output_path']),
32+
'_default' => $this->entrypointFactory($container, '_default', $config['output_path'], $config['cache']),
3333
];
3434
$cacheKeys = [
3535
'_default' => $config['output_path'].'/entrypoints.json',
3636
];
3737
foreach ($config['builds'] as $name => $path) {
38-
$factories[$name] = $this->entrypointFactory($container, $name, $path);
38+
$factories[$name] = $this->entrypointFactory($container, $name, $path, $config['cache']);
3939
$cacheKeys[rawurlencode($name)] = $path;
4040
}
4141

@@ -46,10 +46,10 @@ public function load(array $configs, ContainerBuilder $container)
4646
->replaceArgument(0, ServiceLocatorTagPass::register($container, $factories));
4747
}
4848

49-
private function entrypointFactory(ContainerBuilder $container, string $name, string $path): Reference
49+
private function entrypointFactory(ContainerBuilder $container, string $name, string $path, bool $cacheEnabled): Reference
5050
{
5151
$id = sprintf('webpack_encore.entrypoint_lookup[%s]', $name);
52-
$arguments = [$path.'/entrypoints.json', new Reference('webpack_encore.cache'), $name];
52+
$arguments = [$path.'/entrypoints.json', $cacheEnabled ? new Reference('webpack_encore.cache') : null, $name];
5353
$container->setDefinition($id, new Definition(EntrypointLookup::class, $arguments));
5454

5555
return new Reference($id);

tests/IntegrationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
117117

118118
$container->loadFromExtension('webpack_encore', [
119119
'output_path' => __DIR__.'/fixtures/build',
120+
'cache' => false,
120121
'builds' => [
121122
'different_build' => __DIR__.'/fixtures/different_build'
122123
]

0 commit comments

Comments
 (0)