-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
make tslib imports shakable #16999
Comments
It should be shakable, as the package.json defines |
@bfricka I think the issue is that |
Totally. I should have read the ticket closer. |
That is correct!!! However something like |
Is there anything that would make this unfeasible? It would really be ideal to have only the actually used helpers get bundled by tools like webpack. |
@TheLarkInn, just curious, where can users track better tree-shaking for namespace imports in Webpack? |
Hi there 👋 We faced this issue this week after using generators with typescript while trying not to blow our size budget. Configuration{
"compilerOptions": {
// ...
// We will need typescript not to inline implementation for __generator
"noEmitHelpers": true
// We will need typescript not to import 'tslib' either
"importHelpers": false,
}
} Module using GeneratorFunctions// import __generator manually
import { __generator as tslib__generator } from 'tslib'
// This is necessary so the above import won't get remove on the compiled version
export const __generator = tslib__generator
export function* helloWorld() {
yield* "Hello, World!";
} Outputesm + es2015import { __generator as tslib__generator } from 'tslib';
export const __generator = tslib__generator;
export function* helloWorld() {
yield* Array.from('Hello, World!');
}
//# sourceMappingURL=hello_world.js.map ✅ Using any bundler that does support dead code elimination (a.k.a TreeShaking™), it will ignore esm + es5import { __generator as tslib__generator } from 'tslib';
export var __generator = tslib__generator;
export function helloWorld() {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [5, __values(Array.from('Hello, World!'))];
case 1:
_a.sent();
return [2];
}
});
}
//# sourceMappingURL=hello_world.js.map ✅ Any bundler will see that I hope that this will help some of you until we have proper support for tree shaking of importHelpers. |
Not sure how |
There is a less hacky(in comparison to @fazouane-marouane solution) way to solve the problem
|
I'd like to clarify some of the requirements for tree-shakable imports:
|
It actually looks like it should be enough to change to the |
Ditto the above. An tslib build using Webpack: Rollup: ^ The difference between the two being Rollup will try and determine sideEffects itself while Webpack needs a signal to trigger it's tree-shaking. |
TypeScript Version: 2.4.1
when I use ts with config like:
I notice that it come out with code like this
It is not good enough for tree-shaking by webpack.
Webpack actually bundle with the entire
tslib.es6.js
And it's a bit heavy in my bundle
Expected behavior:
The text was updated successfully, but these errors were encountered: