Let's say I'm running default production
build settings in angular.json
. What happens to all of my unit test and e2e test files (Protractor OR Cypress) when I run npm build --prod
? Are these files included in the final build within the dist
folder, or are they excluded to reduce bundle size? Is this inclusion or exclusion of test files in production builds configurable?
CodePudding user response:
Angular has in its prod build process procedures called "tree-shaking" and, "dead-code elimination". Any code that is not in use by the angular prod app and/or its dependencies is removed from the built code.
This answer provides good details on how it works for angular builds
tl;dr;
If your object/function/class (test or not) is referenced by your components/modules/services/(and other angular blocks or other js/ts code dependencies) it is almost certain to remain into the built app. All other code is removed from the built app.
if you want some code from test files to remain in the built files, you will need to reference that file's exported objects/function from your js files and use that reference somehow.