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
Unused import is created when compiling with NGC #21280
Comments
Rollup should be smart enough to not include |
Yes, check the full description above.
…On Wed, 03 Jan 2018 at 12:40, Sarun Intaralawan ***@***.***> wrote:
Rollup should be smart enough to not include @angular/forms. Have you
tried running rollup yet?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#21280 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQv-WnopezlxEaz0-OXkDTHZAqGVDSD7ks5tG2dDgaJpZM4RRmR3>
.
|
It happens with |
This isn't about angular/packages/compiler-cli/src/main.ts Lines 59 to 64 in f8096d4
TypeScript can either preserve all type annotation imports or drop them all, there's no smart detection in between, so Given all angular packages were marked |
@trotyl, you are right it's due to Though for AOT it will result in an unused import since there won't be any decorator metadata, thus ideally the ngc compiler should elide the unused imports since tsc won't do see microsoft/TypeScript#17552 This is not just due to the bundle size, but also the build time, the more modules you include the slower the build is. Though |
… the never used warnings
@alan-agius4 thank you for pointing the workaround at |
@hpawe01, the CLI already handles this when building the application. How are you experiencing this issue? |
@alan-agius4, I have an Angular library (with latest dependencies), that I build with ivy disabled (for npm publishing). The default And when ngc is bundling the project to
|
Was there any fix or workaround for this ? |
Same issue...
|
The workaround is simply put OnInit etc in a separate import statement. |
@alan-agius4 I don't think it's feasible for The much more practical answer is to not rely on |
Agreed and in the CLI we also have a transformer to elide unused imports. The issue is caused because of a TS issue when using transformers microsoft/TypeScript#17552 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
Angular Compiler is not stripping out unused inputs for classes that are used solely for type definitions.
In the output file generated by
NGC
there is an unused import that is used only for types within the component https://github.com/alan-agius4/angular-ngc-unused-imports/blob/master/ngc-out/main.component.js#L2When using
TSC
there is no unused import https://github.com/alan-agius4/angular-ngc-unused-imports/blob/master/tsc-out/main.component.jsExpected behavior
The import statement is dropped.
Minimal reproduction of the problem with instructions
https://github.com/alan-agius4/angular-ngc-unused-imports
What is the motivation / use case for changing the behavior?
No unused import is created, As when I generate my library and using
rollup
to createFESM
, this will create an import to the whole dependency example;will be transformed to
and like this there will be no treeshaking and the bundle size will eventually increase a lot
Environment
Other details:
microsoft/TypeScript#17552
The text was updated successfully, but these errors were encountered: