Skip to content

Commit 02ce4d8

Browse files
committed
feat(@angular-devkit/build-angular): auto include @angular/platform-server/init during server builds
This changes removes the need to import `@angular/platform-server/init` in the `main.server.ts` instead we now include this as an entry-point when we are bundling as server bundle.
1 parent d18fa89 commit 02ce4d8

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
117117
if (isPlatformServer) {
118118
// Fixes Critical dependency: the request of a dependency is an expression
119119
extraPlugins.push(new ContextReplacementPlugin(/@?hapi|express[\\/]/));
120+
121+
if (Array.isArray(entryPoints['main'])) {
122+
// This import must come before any imports (direct or transitive) that rely on DOM built-ins being
123+
// available, such as `@angular/elements`.
124+
entryPoints['main'].unshift('@angular/platform-server/init');
125+
}
120126
}
121127

122128
if (polyfills?.length) {
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
/***************************************************************************************************
2-
* Initialize the server environment - for example, adding DOM built-in types to the global scope.
3-
*
4-
* NOTE:
5-
* This import must come before any imports (direct or transitive) that rely on DOM built-ins being
6-
* available, such as `@angular/elements`.
7-
*/
8-
import '@angular/platform-server/init';
91

102
export { <%= rootModuleClassName %> } from './app/<%= stripTsExtension(rootModuleFileName) %>';

0 commit comments

Comments
 (0)