-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/build): introduce
ssr.experimentalPlatform
option
This commit introduces a new option called `experimentalPlatform` to the Angular SSR configuration. The `experimentalPlatform` option allows developers to specify the target platform for the server bundle, enabling the generation of platform-neutral bundles suitable for deployment in environments like edge workers and other serverless platforms that do not rely on Node.js APIs. This change enhances the portability of Angular SSR applications and expands their deployment possibilities. **Note:** that this feature does not include polyfills for Node.js modules and is experimental, subject to future changes.
- Loading branch information
1 parent
accaa57
commit 7d883a1
Showing
6 changed files
with
238 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/angular/build/src/tools/esbuild/server-bundle-metadata-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import type { Plugin } from 'esbuild'; | ||
|
||
/** | ||
* Generates an esbuild plugin that appends metadata to the output bundle, | ||
* marking it with server-side rendering (SSR) details for Angular SSR scenarios. | ||
* | ||
* @param options Optional configuration object. | ||
* - `ssrEntryBundle`: If `true`, marks the bundle as an SSR entry point. | ||
* | ||
* @note We can't rely on `platform: node` or `platform: neutral`, as the latter | ||
* is used for non-SSR-related code too (e.g., global scripts). | ||
* @returns An esbuild plugin that injects SSR metadata into the build result's metafile. | ||
*/ | ||
export function createServerBundleMetadata(options?: { ssrEntryBundle?: boolean }): Plugin { | ||
return { | ||
name: 'angular-server-bundle-metadata', | ||
setup(build) { | ||
build.onEnd((result) => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const metafile = result.metafile as any; | ||
if (metafile) { | ||
metafile['ng-ssr-entry-bundle'] = !!options?.ssrEntryBundle; | ||
metafile['ng-platform-server'] = true; | ||
} | ||
}); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.