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.

Named tslib imports cause webpack bundle size increase

See original GitHub issue

TypeScript 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:open
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sokracommented, Aug 22, 2019
import * as ns from "module";
import { abc } from "module";

console.log(ns.abc, abc);

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.

import * as ns from "module";

console.log(ns); // <- all exports of module are included, tree-shaking disabled
0reactions
tommytroylincommented, Sep 2, 2019

according to @sokra and my test based on @RikkiGibson 's demo

latest webpack@4 has already support tree-shaking something like tslib_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.

Read more comments on GitHub >

github_iconTop 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 >

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