Skip to content

Commit f74151b

Browse files
committed
fix(@angular-devkit/build-angular): exclude @angular/platform-server/init from unsafe optimizations
`@angular/platform-server/init` entry-point is side-effectful and thus it's not safe to perform advanced optimizations. (cherry picked from commit 621d088)
1 parent b2ed7bd commit f74151b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/angular_devkit/build_angular/src/babel/webpack-loader.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ export default custom<ApplicationPresetOptions>(() => {
154154
}
155155

156156
if (optimize) {
157-
const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(this.resourcePath);
157+
// @angular/platform-server/init entry-point has side-effects.
158+
const safeAngularPackage =
159+
/[\\/]node_modules[\\/]@angular[\\/]/.test(this.resourcePath) &&
160+
!/@angular[\\/]platform-server[\\/]f?esm2022[\\/]init/.test(this.resourcePath);
158161
customOptions.optimize = {
159162
// Angular packages provide additional tested side effects guarantees and can use
160163
// otherwise unsafe optimizations.
161-
looseEnums: angularPackage,
162-
pureTopLevel: angularPackage,
164+
looseEnums: safeAngularPackage,
165+
pureTopLevel: safeAngularPackage,
163166
// JavaScript modules that are marked as side effect free are considered to have
164167
// no decorators that contain non-local effects.
165168
wrapDecorators: !!this._module?.factoryMeta?.sideEffectFree,

0 commit comments

Comments
 (0)