-
Notifications
You must be signed in to change notification settings - Fork 12k
Option to use ESM instead of FESM for production builds #10754
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
Comments
Webpack 4 |
Can this get some consideration ? I don't get why ng-packagr bothers building ESM files if they are not used. |
@mistic100, FESM are generated from ESM, so they always needs to be built. |
Good to see there is a PR for this :-) Anyway I mistakenly assumed (based on @ToniaDemchuk comment) that importing the FESM bundle prevented webpack to remove unused modules (I try to create a library which exports multiple NgModule), but in fact it works ! |
FESM does indeed shake your unused exports. I do however have a 3th party dependency in my library build which gets bundled with my client-code regardless of it's being used or not. Simplified FESM. import flatpickr from 'flatpickr';
var ButtonComponent = { /* … */ };
var DatePickerComponent = { /* component with dependency on flatpickr */ };
export { ButtonComponent, DatePickerComponent }; When importing only the I was hoping ESM could fix this. |
Lets continue tracking this here: #13635 |
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. |
Versions
6.0.0
Repro steps
ng build --prod
should use ESMs so webpack 4sideEffects
flag can properly prune unused exports. MaybeNormalModuleReplacementPlugin
or something of the like where during prod builds you can swap to the ESM root instead of using the FESM? (I am not sure how involved it is)Observed behavior
Unused exports remain in the bundle, because webpack 4 will not break apart a FESM.
Desired behavior
If I only use
ngModel
in my template, I shouldn't have to pull in all of@angular/forms
.Mention any other details that might be useful (optional)
I am guessing this is already on your radar, but didn't see a formal issue for it.
I did notice the RxJS is packaged in a way that webpack 4
sideEffects
flag prunes unused exports (which is awesome)PS: Upgrade from 5 to 6 was a breeze 👍
Thanks!
Joe
The text was updated successfully, but these errors were encountered: