Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

307
Visualizações
How can I compile globalized assets to a separate bundle using webpack?

I have an app that uses webpack 5 with the HtmlWebpackPlugin to generate HTML for each entry point. The app will be translated into many languages and must load both localized messages that are custom to the app itself as well as localized assets from installed npm modules. I am looking for the best way to incorporate this into our webpack build.

Currently the generated HTML looks like this:

...
<script defer src="/.../app.[content hash].js"></script>
...

Ideally, I'd like to modify this to produce something like the following:

...
<!-- bundle containing localized assets; '{locale}' placeholder to be swapped in for (eg) 'en-US' at runtime when serving up the HTML -->
<script defer src="/.../app.{locale}.[content hash].js"></script>
<!-- bundle containing non-localized assets. Imports from the localized bundle -->
<script defer src="/.../app.[content hash].js"></script>
...

This structure seems appealing because it would (hopefully) make it easy to consume localized assets from within the app's TypeScript code, would only load the assets for the relevant locale, and would allow the localized assets to partake in browser caching based on the content hash.

Is there an easy way to do this with webpack? I've looked at webpack-localize-assets-plugin which offers similar functionality but (a) only produces a single bundle containing all code and localized assets for every locale and (b) requires that localized code use a custom syntax to inject localized strings which isn't obviously compatible with 3rd-party localized assets.

I've also considered simply loading the localized assets dynamically via an AJAX request. This would be simple to do but means no content-based browser caching and also means that code has to handle localized assets coming in asynchronously.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda