question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not reduce bundle size as expected

See original GitHub issue

There is a project that has been written in Typescript. bundle size with babel/preset-env is 101.29KB minified & gzipped also bundle size with babel/preset-modules is 100.27 KB minified & gzipped. here is a repository that you can check: sample-react-redux-typescript I removed polyfills for a better comparison of bundle size. you can run yarn analysis for viewing bundle size. node version: v12.12.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
developitcommented, Nov 18, 2019

@alireza-mh Code imported from node_modules is ES5, regardless of whether it uses ES Modules. This is a common misconception - libraries like react-router-dom and redux don’t actually provide ES2015, they just publish ES5 in a few different module formats. As such, they are entirely unaffected by this preset (whether you run them through Babel or not).

Regarding your repo, I can clarify something: the code isn’t using async/await or Tagged Templates, which are the two syntax features that benefit most from this preset. The code is essentially written in ES2015 (classes, arrow functions), whereas this preset seeks to enable ES2017. It’s likely the only output changes between preset-modules and preset-env for you are arrow functions being used more consistently and slightly worse JSX output (#4 will address).

In general we don’t “modernize” code written in older syntax**, which means optimizations like preset-modules have no effect on that code. In order to see size gains from preset-modules, code needs to be written in ~ES2017 - the more the better.

** I have actually been looking into this space and am working on something.

1reaction
midudevcommented, Nov 19, 2019

@alireza-mh the problem is that what you’re bundling is, probably, already compiled. For example, react and react-dom are already transpiled. Almost everything that’s already in your node_modules is, in fact, already transpiled. That’s why you’re able to ignore them in your webpack.config.js.

So, your improvement of 1KB is from your codebase. Which, is not bad at all, in terms that your app is noticeable small.

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 Methods to Reduce JavaScript Bundle Size - Bits and Pieces
In this article, I will discuss 5 techniques to reduce the JavaScript bundle size to avoid any performance bottlenecks.
Read more >
Slimming down your bundle size - LogRocket Blog
Here are some potential next steps you can take to decrease your bundle size and load time and increase performance. Consider rewriting ......
Read more >
Possible ways to reduce your webpack bundle size - Medium
Here are some cool ways you can reduce your webpack bundle size: ... It can also tell some packages not include debug code....
Read more >
How to easily reduce your NextJS bundle size by 30%?
0. Creating a Baseline · 1. Improve lodash Imports · 2. Use Dynamic Imports · 3. Analyze the Bundle · 4. Do Not...
Read more >
Small Bundles, Fast Pages: What To Do With Too Much ...
This post will explain why bundle size matters and recommend tools and ... visualise, and most importantly, shrink your JS bundles.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found