13
13
use Symfony \Component \DependencyInjection \ContainerBuilder ;
14
14
use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
15
15
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 ;
16
20
17
21
final class WebpackEncoreExtension extends Extension
18
22
{
@@ -24,7 +28,23 @@ public function load(array $configs, ContainerBuilder $container)
24
28
$ configuration = $ this ->getConfiguration ($ configs , $ container );
25
29
$ config = $ this ->processConfiguration ($ configuration , $ configs );
26
30
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
+
27
38
$ 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 ;
29
49
}
30
50
}
0 commit comments