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

131
Visualizações
Webpack dynamic import of images causes large increase in entrypoint size

In Webpack (v5), I started using dynamic imports to include the Twemoji icon set:

require(`twemoji/assets/svg/${filename}.svg`);

There are 3,360 images included by this dynamic import.

I have an asset module to process them:

{
  test: /\.svg$/,
  type: 'asset/resource',
  include: resolve('node_modules', 'twemoji'),
  generator: {
    filename: 'packs/emoji/[name]-[contenthash:8][ext]',
  },
}

Now, the unfortunate result is that this this significantly bloats (~217 KB) the size of my application entrypoint.

This extra data isn't the icons themselves. It's a map of data used by Webpack to find the files.

I was previously using CopyPlugin to achieve a similar result without dynamic imports, and it didn't cause the entrypoint to become bloated. However, it means that I have less control over the assets.

With CopyPlugin, my configuration looked like this:

new CopyPlugin({
  patterns: [{
    from: join(__dirname, '../node_modules/twemoji/assets/svg'),
    to: join(output.path, 'emoji'),
  }],
})

And I was getting the asset URLs as a path to their location:

join(publicPath, `emoji/${filename}.svg`)

So my question is this:

  1. Why does Webpack add this bloat with dynamic imports? Is it already as efficient as it could be?
  2. Is this just a trade-off I have to accept of doing it one way vs the other?
  3. Is there any way to have the advantages of module imports without bloating my bundle, or am I stuck with CopyPlugin?

Note that I'm already using code-splitting in my application, and I intend to separate emojis into its own chunk. But even if it were in its own chunk, I wouldn't want a whole 217 KB of unnecessary data in that chunk.

Thanks in advance for any tips or advice.

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