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

168
Visualizações
Why is a function I expect to be shaken from a tree still there on a create-react-app build?

Similar to Tree shaking create-react-app? but more of how to validate and fix.

So I have a created a library of react hooks. In there I added an example to help me understand how tree-shaking would work.

import { useClock, useDeepState } from '@trajano/react-hooks';
export function App(): JSX.Element {
  useClock();
  useDeepState("foo");
  return <div>Hello world</div>
}

However, there's a function called useAsyncSetEffect that I added in my library code base, but tracing through the code for useClock and useDeepState I don't hit that function at all, but when I look at the generated files I see a reference to useAsyncSetEffect.

Not really sure what's causing it, the library isn't large so the size is just a K gzipped, but I am curious as to why it is being included.

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

0

TL;DR

In package.json "module": "dist/index.modern.js",

How I got to the answer

After trying a few things I found out it's an addition needed on the package.json of my library. Since I am building both modern and cjs using

"build": "microbundle-crl --format modern,cjs",

It generates a version of the code that will make use of the module system. Since it makes use of the module system it is able to tree shake correctly and I reduced the code after.

  44.62 KB (-11.02 KB)  build\static\js\2.7a693cc3.chunk.js
  800 B                 build\static\js\runtime-main.21ea8395.js
  619 B (-601 B)        build\static\js\main.21098aa9.chunk.js

Incidentally it also reduced the code in the 2. chunk which houses more of the React code and it's nice that it significantly reduced it size by 11k

The note about Keeping babel from transpiling ES6 modules to CommonJS modules provided me with the necessary hint. In addition since I know my code was side effect free I also added "sideEffects": false,

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