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

188
Visualizações
How to use code splitting with webpack in react app with components exported as export * from '...'

I'm trying to use code splitting in my react app and overall it works great, but I noticed something strange in bundle analyzer. My components folder is loaded in the first chunk with all its components (even the ones that are only used in lazy loaded components).

I think the problem is that I follow the structure of using index.ts files to export my components: /components:

  • /Component1
    • /Child1
      • Child1.tsx
      • index.ts
    • Component1.tsx
    • index.ts
  • /Component2
    • Component2.tsx
    • index.ts
  • index.ts

The index.ts files just export the needed components like so

export * from './Component';

this is the same as

import { Component } from './Component';

export { Component };

in javascript.

By doing it that way I get very nice looking imports:

import { Component } from 'components';

without the deep paths and all that stuff.

But i think because of that webpack can not recognize how to split it and just bundles it all.

Are there any solutions for this? Maybe I'm doing something wrong?

I use the default create react app config right now.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

export * from './Component';

This is causing webpack to bundle all the components which are there in './Component' and whatever it importing and so on.

You should export components individually without using *

Like export { Component1, Component2 } from './Component'

Also if you are using Webpack 5, it creates a mapping of which component import is used and discard unused components. This is not available in Webpack 4.

about 4 years ago · Juan Pablo Isaza Relatório
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