Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not reduce bundle size as expected #3

Open
alireza-mh opened this issue Nov 17, 2019 · 5 comments
Open

Not reduce bundle size as expected #3

alireza-mh opened this issue Nov 17, 2019 · 5 comments
Labels
discussion documentation Improvements or additions to documentation

Comments

@alireza-mh
Copy link

alireza-mh commented Nov 17, 2019

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

@peter-mouland
Copy link

peter-mouland commented Nov 17, 2019

it depends on the output of the original bundle, but for me it will. here are some of my own test changes (with loose=true):

Rest

  • webpack output length from 5696 to 4467
  • rollup output length from 258 to 187
    image

Template Strings

  • webpack output length from 4380 to 4375
  • rollup output length from 100 to 95
    image

nice little update 👍

@midudev
Copy link

midudev commented Nov 18, 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.

@alireza-mh
Copy link
Author

I removed node_module exclude from babel and ts loaders and faced the same bundle size.
(some of the packages like react-router-dom have esm folder)
I also checked this on the medium size project (400 KB minified and gzip) but the bundle size has been reduced by 2 KB.

@developit
Copy link
Member

developit commented 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.

@matzeeable
Copy link

Just came across this issue and just want to know if there are any news about your implementation, @developit ? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants