Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): auto include `@angular/platform-…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
alan-agius4 committed Oct 12, 2022
1 parent a95d130 commit 979bce4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Expand Up @@ -117,6 +117,12 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
if (isPlatformServer) {
// Fixes Critical dependency: the request of a dependency is an expression
extraPlugins.push(new ContextReplacementPlugin(/@?hapi|express[\\/]/));

if (Array.isArray(entryPoints['main'])) {
// This import must come before any imports (direct or transitive) that rely on DOM built-ins being
// available, such as `@angular/elements`.
entryPoints['main'].unshift('@angular/platform-server/init');
}
}

if (polyfills?.length) {
Expand Down
@@ -1,10 +1,2 @@
/***************************************************************************************************
* Initialize the server environment - for example, adding DOM built-in types to the global scope.
*
* NOTE:
* This import must come before any imports (direct or transitive) that rely on DOM built-ins being
* available, such as `@angular/elements`.
*/
import '@angular/platform-server/init';

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

0 comments on commit 979bce4

Please sign in to comment.