Allow to set attributes per build
Currently i'm creating two builds, a modern and a legacy, and serving them both with type=module and nomodule. To do so i've created twig functions to add the correct attributes to both builds. It would be easier if this could be done inside of the config.
The twig function for reference:
public function getFunctions(): array
{
return [
new TwigFunction('script_tags', [$this, 'legacyEntry'], ['is_safe' => ['html']]),
];
}
public function legacyEntry($name): string
{
return $this->tagRenderer->renderWebpackScriptTags($name, null, 'legacy', ['nomodule' => null]) .
$this->tagRenderer->renderWebpackScriptTags($name, null, 'modern', ['type' => 'module']);
}
Hi @BackEndTea,
Does Defining Multiple Webpack Configurations from the documentation could help you in any way?
I have the feeling that this is more a feature request for the EncoreBundle than for Encore itself.
@BackEndTea first of all - thanks for a nice article described the way you handled module-nomodule config. But. as @CyrilKrylatov says - I did it by using multiple webpack config.
Only thing I changed for legacy part - added encore way babel config. And it works. At least page speed does not say anything after such implementation.