Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!