Named tslib imports cause webpack bundle size increase
See original GitHub issueTypeScript Version: 3.6.1-rc
Search Terms: tslib
Expected behavior:
#32742, which changes all tslib
imports from namespace imports to named imports, would have decreased bundle size in webpack builds from typescript code
Actual behavior:
Due to a quirky workaround in webpack
, all function invocations of named harmony imports are wrapped in an Object()
constructor; as a result, #32742 actually increases bundle size (to the tune of ~9kB in Outlook Web boot bundles)
Since the PR was an attempt specifically to help webpack, and @sokra claims that tree-shaking works even with namespace imports, I think the change should be reverted.
Related Issues: webpack/webpack#9615
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Use TSLIB to reduce your TypeScript bundle size - YouTube
In this tutorial we will look at how these utility functions can increase the size of your bundle and how you can use...
Read more >Optimizing bundle size with TSLib helper functions
The lib is quite small yet it's tree-shakeable which means good bundler won't use any unneeded functions.
Read more >How we reduced our initial JS/CSS size by 67% - Blog - Fider
Webpack will ALWAYS regenerate the main bundle if something else changes in your application. The reason being that the main bundle is a...
Read more >Webpack import causing massive bundle size even with ...
// Importing this similarly causes all dependencies to bundle and 30+mb bundle size export ; const getWebAccessInfo = function ; checkFrames =Β ...
Read more >Shimming - webpack
Let's go ahead by removing the import statement for lodash and instead provide it ... load all polyfills/shims, despite the bundle size cost...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Both can be tree-shaken equally. This has always been the case.
Some claims say that namespace objects are not tree-shake-able, but this is only true when using the namespace object directly, without accessing a property of it.
according to @sokra and my test based on @RikkiGibson 's demo
latest
webpack@4
has already support tree-shaking something liketslib_1.__assign
@sokra I could barely remember when tree-shaking comes out on
webpack@2or3
, namespace imports are not shakeable. Iβm not sure.back to #16999, I canβt reproduce that build now but we actually notice that behaviour years ago.
IMO, if tests confirm that on
webpack@3or4
with proper configs tree-shaking works as expected. Reverting that outdated optimization is acceptable.