-
Notifications
You must be signed in to change notification settings - Fork 14
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
[Request] Decrease the bundle size #203
Comments
Hey @edsrzf, those are some nice suggestions and we would appreciate your help. For starters, I have created this PR: #204 that addresses the following and is reducing the bundle size for the browser version by around 40K minified:
For the latter, native |
Thanks! For the next major release, I'd note that the oldest currently-supported version of Node is 18, and so it shouldn't be much of a leap for most to use native fetch. (Though technically |
First batch of optimizations have been released on |
Given the fact Node 16 is now well past End of Life (https://nodejs.org/en/blog/announcements/nodejs16-eol), can you bump the Node version from 16 to 18 as the minimum, and drop That would provide another sizeable decrease in bundle size. |
Current Behavior
@transifex/native
increases bundle size significantly when added as a dependency. Bundlephobia says it's 135.7kb minified and 43.2kb minified/gzipped, which is in line with what we're seeing in our bundles. This is larger thanreact
andreact-dom
combined, which is fairly ridiculous.Expected Behavior
@transifex/native
should ideally be more like 30-40kb minified.Steps to Reproduce
Add
@transifex/native
as a dependency and bundle your application.Possible Solution
I have four suggestions that could improve the situation. Two of these could be considered breaking changes and would require a major version bump, but would not necessarily be difficult upgrades for people to make. I've noted which ones below.
The general themes of these suggestions are:
If any of these suggestions are interesting, we could split them out into separate issues. I'd also be willing to help with some of them.
Transpile Fewer Features
This would be a breaking change.
Currently all the packages in this repo use
@babel/preset-env
with defaults, which targets extremely old browsers, and thus has to emit quite a bit more code during transpilation.I can't speak for all users of these packages, but we would be totally fine targeting ES2018+, removing the need to transpile most or possibly even all the code in
@transifex/native
. All major browsers have supported these features for nearly 4 years.@messageformat/core
already uses the browserlist query:This is equivalent to browserlists'
defaults
and seems like a reasonable starting point.People who care about older browsers still have the option of transpiling dependencies.
If I remove
babel-loader
from the browser Webpack config, the browser bundle goes from 136kb to 119kb.Ship an ES Module Bundle
This would not need to be a breaking change, since it could be additive.
Browsers commonly support ES modules, and modern bundlers like Rollup and Webpack prefer working with ES modules. ES modules allow for easier size optimization through tree-shaking.
For people who care about older environments, you could continue shipping a UMD or CommonJS bundle alongside the ES module one.
If I enable experiment module output in Webpack and set
output.library.type
to'module'
, the browser bundle actually increases slightly from 119kb to 120kb. I'm hopeful that we could make up for this in the final application with tree-shaking.Remove Axios
This would be a breaking change.
The fetch API is widely supported in browsers and in all current versions of Node. It should provide functionality to replace Axios, which is 11.6kb minified/gzipped -- roughly a quarter of
@transifex/native
's size.For people who care about older environments, you could provide a way to pass in a
fetch
function. They could then choose to pull in a fetch polyfill and pass that in.If I remove Axios and replace it with
fetch
, the browser bundle goes from 120kb down to 91kb.Treat Dependencies as External
This would not need to be a breaking change (IMO).
@transifex/native
bundles its dependencies, but also lists them insidepackage.json
underdependencies
, which is redundant since they aren't actually needed at runtime. It should either:devDependencies
I would prefer the first. That would:
@transifex/native
itselfmd5
, which would save us 2.2kb minified/gzipped. Not huge, but I'll take free savings if I can get it.)I can see there's further room for improvement in
@messageformat/core
, but I can take that up with that project if we can get started on some of the improvements here.The text was updated successfully, but these errors were encountered: