angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Angular cli - not removing dependencies of unused library components

Open babeal opened this issue 8 years ago • 22 comments

Bug Report or Feature Request (mark with an x)

- [x ] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [x] build

Versions

Npm: 6.4.1 Angular CLI: 7.1.0 Node: 10.14.0 OS: darwin x64 Angular: 7.1.1 ... animations, common, compiler, compiler-cli, core, forms ... language-service, platform-browser, platform-browser-dynamic ... router

Package Version

@angular-devkit/architect 0.11.0 @angular-devkit/build-angular 0.11.0 @angular-devkit/build-ng-packagr 0.11.0 @angular-devkit/build-optimizer 0.11.0 @angular-devkit/build-webpack 0.11.0 @angular-devkit/core 7.1.0 @angular-devkit/schematics 7.1.0 @angular/cli 7.1.0 @ngtools/json-schema 1.1.0 @ngtools/webpack 7.1.0 @schematics/angular 7.1.0 @schematics/update 0.11.0 ng-packagr 4.4.0 rxjs 6.3.3 typescript 3.1.6 webpack 4.23.1

Repro steps

The angular build/packaging process is unable to remove third party dependencies from unused components in a library. The example provided includes a library called components containing a component that imports moment.js and one that doesn't. When only the component that DOES NOT use moment is imported into the application the resulting application bundle will still contain moment. I have tried to force the build process to use esm5 instead of fesm 5 and this does not help. The only thing left referencing moment would be the metadata.json. This problem makes it difficult to build large component libraries using the cli due to the fact that all runtime transitive dependencies will be included in the final bundle whether they are used or not. I would like to know why this is and where the problem resides.

https://github.com/babeal/ng-tdp

clone, run npm install, then npm run analyze

The log given by the failure

The results of the webpack analysis will show moment in the main bundle as well as inspecting the minified main.js in the dist folder.

Desired functionality

Should not include unused external dependencies into the final bundle

Mention any other details that might be useful

babeal avatar Nov 29 '18 03:11 babeal

Hi @schallus, Unfortunatelly nothing to share. Waiting for @filipesilva response. Will wait for some time and raise new ticket there.

yansokalau avatar Mar 29 '19 08:03 yansokalau

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.