@nx/angular-rspack 24.0.0-beta.2 → 24.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/config/config-utils/browser-config.d.ts +2 -1
- package/dist/lib/config/config-utils/browser-config.d.ts.map +1 -1
- package/dist/lib/config/config-utils/browser-config.js +2 -1
- package/dist/lib/config/config-utils/server-config.d.ts +2 -1
- package/dist/lib/config/config-utils/server-config.d.ts.map +1 -1
- package/dist/lib/config/config-utils/server-config.js +29 -3
- package/dist/lib/config/create-config.d.ts.map +1 -1
- package/dist/lib/config/create-config.js +5 -2
- package/dist/lib/models/augmented-compilation.d.ts +2 -2
- package/dist/lib/models/augmented-compilation.d.ts.map +1 -1
- package/dist/lib/plugins/angular-rspack-plugin.d.ts.map +1 -1
- package/dist/lib/plugins/angular-rspack-plugin.js +2 -2
- package/dist/lib/plugins/extract-licenses-plugin.d.ts +4 -4
- package/dist/lib/plugins/extract-licenses-plugin.d.ts.map +1 -1
- package/dist/lib/plugins/extract-licenses-plugin.js +43 -13
- package/dist/lib/plugins/index-html-plugin.d.ts +35 -0
- package/dist/lib/plugins/index-html-plugin.d.ts.map +1 -1
- package/dist/lib/plugins/index-html-plugin.js +138 -3
- package/dist/lib/plugins/loaders/angular-partial-transform.loader.d.ts.map +1 -1
- package/dist/lib/plugins/loaders/angular-partial-transform.loader.js +5 -7
- package/dist/lib/plugins/loaders/engine-manifest.d.ts +5 -2
- package/dist/lib/plugins/loaders/engine-manifest.d.ts.map +1 -1
- package/dist/lib/plugins/loaders/engine-manifest.js +9 -4
- package/dist/lib/plugins/ng-rspack.d.ts +7 -0
- package/dist/lib/plugins/ng-rspack.d.ts.map +1 -1
- package/dist/lib/plugins/ng-rspack.js +2 -0
- package/dist/lib/plugins/prerender-plugin.d.ts +2 -1
- package/dist/lib/plugins/prerender-plugin.d.ts.map +1 -1
- package/dist/lib/plugins/prerender-plugin.js +40 -23
- package/dist/lib/plugins/server-assets-plugin.d.ts +13 -0
- package/dist/lib/plugins/server-assets-plugin.d.ts.map +1 -0
- package/dist/lib/plugins/server-assets-plugin.js +42 -0
- package/dist/lib/plugins/tools/render-worker.d.ts +24 -1
- package/dist/lib/plugins/tools/render-worker.d.ts.map +1 -1
- package/dist/lib/plugins/tools/render-worker.js +48 -19
- package/dist/lib/ssr/server-assets.d.ts +29 -13
- package/dist/lib/ssr/server-assets.d.ts.map +1 -1
- package/dist/lib/ssr/server-assets.js +57 -34
- package/dist/lib/utils/beasties.d.ts +35 -0
- package/dist/lib/utils/beasties.d.ts.map +1 -0
- package/dist/lib/utils/beasties.js +11 -0
- package/dist/lib/utils/index-file/ngcm-attribute.d.ts +16 -0
- package/dist/lib/utils/index-file/ngcm-attribute.d.ts.map +1 -0
- package/dist/lib/utils/index-file/ngcm-attribute.js +37 -0
- package/dist/lib/utils/index-file/nonce.d.ts +15 -0
- package/dist/lib/utils/index-file/nonce.d.ts.map +1 -0
- package/dist/lib/utils/index-file/nonce.js +54 -0
- package/package.json +3 -3
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = loader;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
4
|
const angular_rspack_compiler_1 = require("@nx/angular-rspack-compiler");
|
|
6
5
|
const models_1 = require("../../models");
|
|
7
6
|
const inline_source_map_1 = require("./inline-source-map");
|
|
@@ -82,13 +81,12 @@ function loader(content, inputMap) {
|
|
|
82
81
|
}
|
|
83
82
|
// A mismatched entry means the chained map changed since the entry was
|
|
84
83
|
// produced. The transformer's persistent cache is keyed on the file
|
|
85
|
-
// bytes only, so `transformFile` would return the same stale output
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
// there, matching the esbuild application builder's behavior.
|
|
84
|
+
// bytes only, so `transformFile` would return the same stale output. A
|
|
85
|
+
// cold process has no entry to compare against, so a stale persistent
|
|
86
|
+
// entry can still be served there, matching the esbuild application
|
|
87
|
+
// builder's behavior.
|
|
90
88
|
const transformed = cachedTransform !== undefined
|
|
91
|
-
?
|
|
89
|
+
? javascriptTransformer.transformFileUncached(request, false, false)
|
|
92
90
|
: javascriptTransformer.transformFile(request, false, false);
|
|
93
91
|
transformed.then((contents) => {
|
|
94
92
|
const text = Buffer.from(contents).toString('utf8');
|
|
@@ -9,10 +9,13 @@ export interface EngineWiringOptions {
|
|
|
9
9
|
baseHref: string;
|
|
10
10
|
locale: string | undefined;
|
|
11
11
|
inlineCriticalCss: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the installed `@angular/ssr` (>= 22.2) inlines critical CSS from
|
|
14
|
+
* plans compiled at build time instead of from the browser stylesheets.
|
|
15
|
+
*/
|
|
16
|
+
usesCriticalCssPlans: boolean;
|
|
12
17
|
/** Path from the server output directory to the browser output. */
|
|
13
18
|
browserOutputRelativePath: string;
|
|
14
|
-
/** File name of the emitted index html within the browser output. */
|
|
15
|
-
indexOutputName: string | undefined;
|
|
16
19
|
supportedLocales: Record<string, string>;
|
|
17
20
|
allowedHosts: string[];
|
|
18
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-manifest.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/loaders/engine-manifest.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,4BAA4B,wCACF,CAAC;AAExC,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,iBAAiB,EAAE,OAAO,CAAC;IAC3B
|
|
1
|
+
{"version":3,"file":"engine-manifest.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/loaders/engine-manifest.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,4BAA4B,wCACF,CAAC;AAExC,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,iBAAiB,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B,mEAAmE;IACnE,yBAAyB,EAAE,MAAM,CAAC;IAClC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,mBAAmB,GAChC,MAAM,CA4ER"}
|
|
@@ -34,19 +34,24 @@ function generateEngineManifestSource(engineWiring) {
|
|
|
34
34
|
ɵgetOrCreateAngularServerApp as __ngRspackGetOrCreateAngularServerApp,
|
|
35
35
|
ɵdestroyAngularServerApp as __ngRspackDestroyAngularServerApp,
|
|
36
36
|
} from '@angular/ssr';
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
createServerAssets as __ngRspackCreateServerAssets,
|
|
39
|
+
readCriticalCss as __ngRspackReadCriticalCss,
|
|
40
|
+
} from ${serverAssetsRequest};
|
|
38
41
|
import { join as __ngRspackJoinPath } from 'node:path';
|
|
39
42
|
// MANIFESTS added by @nx/angular-rspack: an application engine cannot
|
|
40
43
|
// construct without them.
|
|
41
44
|
__ngRspackSetAngularAppManifest({
|
|
42
45
|
bootstrap: () => Promise.resolve(__ngRspackMainServerDefault),
|
|
43
|
-
|
|
46
|
+
${engineWiring.usesCriticalCssPlans
|
|
47
|
+
? '...__ngRspackReadCriticalCss(__dirname),'
|
|
48
|
+
: `inlineCriticalCss: ${JSON.stringify(engineWiring.inlineCriticalCss)},`}
|
|
44
49
|
baseHref: ${JSON.stringify(engineWiring.baseHref)},
|
|
45
50
|
locale: ${JSON.stringify(engineWiring.locale)},
|
|
46
51
|
assets: __ngRspackCreateServerAssets(
|
|
52
|
+
__dirname,
|
|
47
53
|
__ngRspackJoinPath(__dirname, ${JSON.stringify(engineWiring.browserOutputRelativePath)}),
|
|
48
|
-
${JSON.stringify(engineWiring.
|
|
49
|
-
${JSON.stringify(engineWiring.inlineCriticalCss)}
|
|
54
|
+
${JSON.stringify(!engineWiring.usesCriticalCssPlans && engineWiring.inlineCriticalCss)}
|
|
50
55
|
),
|
|
51
56
|
});
|
|
52
57
|
__ngRspackSetAngularAppEngineManifest({
|
|
@@ -2,12 +2,14 @@ import { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
|
2
2
|
import type { I18nOptions, NormalizedAngularRspackPluginOptions } from '../models';
|
|
3
3
|
import { AngularRspackPlugin } from './angular-rspack-plugin';
|
|
4
4
|
import { type SharedLicenseInputs } from './extract-licenses-plugin';
|
|
5
|
+
import { type SharedServerRenderingInputs } from './index-html-plugin';
|
|
5
6
|
export declare class NgRspackPlugin implements RspackPluginInstance {
|
|
6
7
|
readonly pluginOptions: NormalizedAngularRspackPluginOptions;
|
|
7
8
|
readonly isPlatformServer: boolean;
|
|
8
9
|
readonly i18n: I18nOptions;
|
|
9
10
|
private readonly sharedLicenseInputs;
|
|
10
11
|
private readonly sharedAngularPlugin;
|
|
12
|
+
private readonly serverRenderingInputs;
|
|
11
13
|
constructor(pluginOptions: NormalizedAngularRspackPluginOptions, extraOptions: {
|
|
12
14
|
platform: 'browser' | 'server';
|
|
13
15
|
i18nOptions: I18nOptions;
|
|
@@ -25,6 +27,11 @@ export declare class NgRspackPlugin implements RspackPluginInstance {
|
|
|
25
27
|
* own compilation.
|
|
26
28
|
*/
|
|
27
29
|
sharedAngularPlugin?: AngularRspackPlugin;
|
|
30
|
+
/**
|
|
31
|
+
* Filled by the browser compiler of an SSR build for the server
|
|
32
|
+
* compiler.
|
|
33
|
+
*/
|
|
34
|
+
serverRenderingInputs?: SharedServerRenderingInputs;
|
|
28
35
|
});
|
|
29
36
|
apply(compiler: Compiler): void;
|
|
30
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-rspack.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/ng-rspack.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAGR,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EACV,WAAW,EACX,oCAAoC,EACrC,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"ng-rspack.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/ng-rspack.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAGR,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EACV,WAAW,EACX,oCAAoC,EACrC,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,qBAAqB,CAAC;AAI7B,qBAAa,cAAe,YAAW,oBAAoB;IACzD,QAAQ,CAAC,aAAa,EAAE,oCAAoC,CAAC;IAC7D,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAkC;IACtE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAkC;IACtE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAExB;IAEd,YACE,aAAa,EAAE,oCAAoC,EACnD,YAAY,EAAE;QACZ,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAC;QAC/B,WAAW,EAAE,WAAW,CAAC;QACzB;;;;WAIG;QACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;QAC1C;;;;;;WAMG;QACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;QAC1C;;;WAGG;QACH,qBAAqB,CAAC,EAAE,2BAA2B,CAAC;KACrD,EAQF;IAED,KAAK,CAAC,QAAQ,EAAE,QAAQ,QA4MvB;CACF"}
|
|
@@ -21,6 +21,7 @@ class NgRspackPlugin {
|
|
|
21
21
|
this.isPlatformServer = extraOptions.platform === 'server';
|
|
22
22
|
this.sharedLicenseInputs = extraOptions.sharedLicenseInputs;
|
|
23
23
|
this.sharedAngularPlugin = extraOptions.sharedAngularPlugin;
|
|
24
|
+
this.serverRenderingInputs = extraOptions.serverRenderingInputs;
|
|
24
25
|
}
|
|
25
26
|
apply(compiler) {
|
|
26
27
|
const root = this.pluginOptions.root;
|
|
@@ -147,6 +148,7 @@ class NgRspackPlugin {
|
|
|
147
148
|
chunksIntegrity: this.pluginOptions.subresourceIntegrity
|
|
148
149
|
? new Map()
|
|
149
150
|
: undefined,
|
|
151
|
+
serverRenderingInputs: this.serverRenderingInputs,
|
|
150
152
|
}).apply(compiler);
|
|
151
153
|
}
|
|
152
154
|
if (this.pluginOptions.devServer.open &&
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
2
|
import { type I18nOptions, NormalizedAngularRspackPluginOptions } from '../models';
|
|
3
|
+
import { type SharedServerRenderingInputs } from './index-html-plugin';
|
|
3
4
|
export declare class PrerenderPlugin implements RspackPluginInstance {
|
|
4
5
|
#private;
|
|
5
|
-
constructor(options: NormalizedAngularRspackPluginOptions, i18nOptions?: I18nOptions);
|
|
6
|
+
constructor(options: NormalizedAngularRspackPluginOptions, i18nOptions?: I18nOptions, serverRenderingInputs?: SharedServerRenderingInputs);
|
|
6
7
|
apply(compiler: Compiler): void;
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=prerender-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prerender-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/prerender-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,QAAQ,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOhF,OAAO,EACL,KAAK,WAAW,EAEhB,oCAAoC,EACrC,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"prerender-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/prerender-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,QAAQ,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOhF,OAAO,EACL,KAAK,WAAW,EAEhB,oCAAoC,EACrC,MAAM,WAAW,CAAC;AAYnB,OAAO,EAGL,KAAK,2BAA2B,EACjC,MAAM,qBAAqB,CAAC;AAQ7B,qBAAa,eAAgB,YAAW,oBAAoB;;IAK1D,YACE,OAAO,EAAE,oCAAoC,EAC7C,WAAW,CAAC,EAAE,WAAW,EACzB,qBAAqB,CAAC,EAAE,2BAA2B,EAKpD;IAED,KAAK,CAAC,QAAQ,EAAE,QAAQ,QAoCvB;CAmTF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _PrerenderPlugin_instances, _PrerenderPlugin__options, _PrerenderPlugin_i18n, _PrerenderPlugin_writePrerenderedRoutesManifest, _PrerenderPlugin_prerenderAppShell, _PrerenderPlugin_prerenderSSGUniversal, _PrerenderPlugin_getRoutes, _PrerenderPlugin_normalizePrerenderOptions, _PrerenderPlugin_resolveZonePackage;
|
|
2
|
+
var _PrerenderPlugin_instances, _PrerenderPlugin__options, _PrerenderPlugin_i18n, _PrerenderPlugin_serverRenderingInputs, _PrerenderPlugin_writePrerenderedRoutesManifest, _PrerenderPlugin_prerenderAppShell, _PrerenderPlugin_prerenderSSGUniversal, _PrerenderPlugin_getRoutes, _PrerenderPlugin_normalizePrerenderOptions, _PrerenderPlugin_createRenderWorkerPool, _PrerenderPlugin_getDocumentRenderOptions, _PrerenderPlugin_resolveZonePackage;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.PrerenderPlugin = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
@@ -15,28 +15,37 @@ const max_workers_1 = require("../utils/max-workers");
|
|
|
15
15
|
const i18n_1 = require("../utils/i18n");
|
|
16
16
|
const rspack_diagnostics_1 = require("../utils/rspack-diagnostics");
|
|
17
17
|
const misc_helpers_1 = require("../utils/misc-helpers");
|
|
18
|
+
const index_html_plugin_1 = require("./index-html-plugin");
|
|
18
19
|
class RoutesSet extends Set {
|
|
19
20
|
add(value) {
|
|
20
21
|
return super.add(value.charAt(0) === '/' ? value.slice(1) : value);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
class PrerenderPlugin {
|
|
24
|
-
constructor(options, i18nOptions) {
|
|
25
|
+
constructor(options, i18nOptions, serverRenderingInputs) {
|
|
25
26
|
_PrerenderPlugin_instances.add(this);
|
|
26
27
|
_PrerenderPlugin__options.set(this, void 0);
|
|
27
28
|
_PrerenderPlugin_i18n.set(this, void 0);
|
|
29
|
+
_PrerenderPlugin_serverRenderingInputs.set(this, void 0);
|
|
28
30
|
tslib_1.__classPrivateFieldSet(this, _PrerenderPlugin__options, options, "f");
|
|
29
31
|
tslib_1.__classPrivateFieldSet(this, _PrerenderPlugin_i18n, i18nOptions, "f");
|
|
32
|
+
tslib_1.__classPrivateFieldSet(this, _PrerenderPlugin_serverRenderingInputs, serverRenderingInputs, "f");
|
|
30
33
|
}
|
|
31
34
|
apply(compiler) {
|
|
32
35
|
compiler.hooks.afterEmit.tapAsync('Angular Rspack', async (compilation, callback) => {
|
|
36
|
+
const inputs = tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_serverRenderingInputs, "f")?.current;
|
|
37
|
+
if (!inputs) {
|
|
38
|
+
(0, rspack_diagnostics_1.addError)(compilation, 'Could not prerender because the browser build did not generate the index html.');
|
|
39
|
+
callback();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
33
42
|
const prerenderedRoutes = new Set();
|
|
34
43
|
if (tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").appShell) {
|
|
35
|
-
await tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_prerenderAppShell).call(this, compilation);
|
|
44
|
+
await tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_prerenderAppShell).call(this, compilation, inputs);
|
|
36
45
|
prerenderedRoutes.add('/');
|
|
37
46
|
}
|
|
38
47
|
if (tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").prerender) {
|
|
39
|
-
for (const route of await tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_prerenderSSGUniversal).call(this, compilation)) {
|
|
48
|
+
for (const route of await tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_prerenderSSGUniversal).call(this, compilation, inputs)) {
|
|
40
49
|
// RoutesSet stores routes without the leading slash; the manifest
|
|
41
50
|
// keys carry it, matching the esbuild application builder.
|
|
42
51
|
prerenderedRoutes.add(`/${route}`);
|
|
@@ -48,7 +57,7 @@ class PrerenderPlugin {
|
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
exports.PrerenderPlugin = PrerenderPlugin;
|
|
51
|
-
_PrerenderPlugin__options = new WeakMap(), _PrerenderPlugin_i18n = new WeakMap(), _PrerenderPlugin_instances = new WeakSet(), _PrerenderPlugin_writePrerenderedRoutesManifest =
|
|
60
|
+
_PrerenderPlugin__options = new WeakMap(), _PrerenderPlugin_i18n = new WeakMap(), _PrerenderPlugin_serverRenderingInputs = new WeakMap(), _PrerenderPlugin_instances = new WeakSet(), _PrerenderPlugin_writePrerenderedRoutesManifest =
|
|
52
61
|
/**
|
|
53
62
|
* Overwrites the empty `prerendered-routes.json` emitted at the output root
|
|
54
63
|
* by the browser compiler with the routes that were prerendered.
|
|
@@ -63,17 +72,10 @@ async function _PrerenderPlugin_writePrerenderedRoutesManifest(compilation, prer
|
|
|
63
72
|
(0, misc_helpers_1.assertIsError)(error);
|
|
64
73
|
(0, rspack_diagnostics_1.addError)(compilation, error.message);
|
|
65
74
|
}
|
|
66
|
-
}, _PrerenderPlugin_prerenderAppShell = async function _PrerenderPlugin_prerenderAppShell(compilation) {
|
|
75
|
+
}, _PrerenderPlugin_prerenderAppShell = async function _PrerenderPlugin_prerenderAppShell(compilation, inputs) {
|
|
67
76
|
// Users can specify a different base html file e.g. "src/home.html"
|
|
68
77
|
const indexFile = (0, get_index_output_file_1.getIndexOutputFile)(tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").index);
|
|
69
|
-
const worker =
|
|
70
|
-
filename: require.resolve('./tools/render-worker'),
|
|
71
|
-
maxThreads: (0, max_workers_1.maxWorkers)(),
|
|
72
|
-
workerData: {
|
|
73
|
-
zonePackage: tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_resolveZonePackage).call(this, devkit_1.workspaceRoot),
|
|
74
|
-
},
|
|
75
|
-
recordTiming: false,
|
|
76
|
-
});
|
|
78
|
+
const worker = tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_createRenderWorkerPool).call(this, inputs);
|
|
77
79
|
try {
|
|
78
80
|
const outputPaths = tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_i18n, "f")
|
|
79
81
|
? (0, i18n_1.ensureOutputPaths)(tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").outputPath.browser, tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_i18n, "f"))
|
|
@@ -91,7 +93,9 @@ async function _PrerenderPlugin_writePrerenderedRoutesManifest(compilation, prer
|
|
|
91
93
|
}
|
|
92
94
|
try {
|
|
93
95
|
const options = {
|
|
96
|
+
...tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_getDocumentRenderOptions).call(this, inputs, locale),
|
|
94
97
|
indexFile,
|
|
98
|
+
emitsOriginalIndex: (0, index_html_plugin_1.emitsServerIndexAsOriginal)(tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").index),
|
|
95
99
|
deployUrl: tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").deployUrl || '',
|
|
96
100
|
inlineCriticalCss: !!tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").optimization.styles.inlineCritical,
|
|
97
101
|
minifyCss: !!tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").optimization.styles.minify,
|
|
@@ -125,17 +129,10 @@ async function _PrerenderPlugin_writePrerenderedRoutesManifest(compilation, prer
|
|
|
125
129
|
finally {
|
|
126
130
|
void worker.destroy();
|
|
127
131
|
}
|
|
128
|
-
}, _PrerenderPlugin_prerenderSSGUniversal = async function _PrerenderPlugin_prerenderSSGUniversal(compilation) {
|
|
132
|
+
}, _PrerenderPlugin_prerenderSSGUniversal = async function _PrerenderPlugin_prerenderSSGUniversal(compilation, inputs) {
|
|
129
133
|
// Users can specify a different base html file e.g. "src/home.html"
|
|
130
134
|
const indexFile = (0, get_index_output_file_1.getIndexOutputFile)(tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").index);
|
|
131
|
-
const worker =
|
|
132
|
-
filename: require.resolve('./tools/render-worker'),
|
|
133
|
-
maxThreads: (0, max_workers_1.maxWorkers)(),
|
|
134
|
-
workerData: {
|
|
135
|
-
zonePackage: tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_resolveZonePackage).call(this, devkit_1.workspaceRoot),
|
|
136
|
-
},
|
|
137
|
-
recordTiming: false,
|
|
138
|
-
});
|
|
135
|
+
const worker = tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_createRenderWorkerPool).call(this, inputs);
|
|
139
136
|
let routes;
|
|
140
137
|
try {
|
|
141
138
|
const outputPaths = tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_i18n, "f")
|
|
@@ -154,9 +151,13 @@ async function _PrerenderPlugin_writePrerenderedRoutesManifest(compilation, prer
|
|
|
154
151
|
}
|
|
155
152
|
routes ??= await tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_getRoutes).call(this, indexFile, normalizedOutputPath, serverBundlePath, devkit_1.workspaceRoot);
|
|
156
153
|
try {
|
|
154
|
+
const documentRenderOptions = tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_getDocumentRenderOptions).call(this, inputs, locale);
|
|
155
|
+
const emitsOriginalIndex = (0, index_html_plugin_1.emitsServerIndexAsOriginal)(tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").index);
|
|
157
156
|
const results = (await Promise.all(routes.map((route) => {
|
|
158
157
|
const options = {
|
|
158
|
+
...documentRenderOptions,
|
|
159
159
|
indexFile,
|
|
160
|
+
emitsOriginalIndex,
|
|
160
161
|
deployUrl: tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").deployUrl || '',
|
|
161
162
|
inlineCriticalCss: !!tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").optimization.styles.inlineCritical,
|
|
162
163
|
minifyCss: !!tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").optimization.styles.minify,
|
|
@@ -232,6 +233,22 @@ async function _PrerenderPlugin_writePrerenderedRoutesManifest(compilation, prer
|
|
|
232
233
|
};
|
|
233
234
|
}
|
|
234
235
|
return tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").prerender;
|
|
236
|
+
}, _PrerenderPlugin_createRenderWorkerPool = function _PrerenderPlugin_createRenderWorkerPool(inputs) {
|
|
237
|
+
return new worker_pool_1.WorkerPool({
|
|
238
|
+
filename: require.resolve('./tools/render-worker'),
|
|
239
|
+
maxThreads: (0, max_workers_1.maxWorkers)(),
|
|
240
|
+
workerData: {
|
|
241
|
+
zonePackage: tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin_instances, "m", _PrerenderPlugin_resolveZonePackage).call(this, devkit_1.workspaceRoot),
|
|
242
|
+
criticalCssPlans: inputs.criticalCssPlans,
|
|
243
|
+
},
|
|
244
|
+
recordTiming: false,
|
|
245
|
+
});
|
|
246
|
+
}, _PrerenderPlugin_getDocumentRenderOptions = function _PrerenderPlugin_getDocumentRenderOptions(inputs, locale) {
|
|
247
|
+
const indexHtml = inputs.indexHtml.get(locale);
|
|
248
|
+
if (!indexHtml) {
|
|
249
|
+
throw new Error(`Could not find the index html generated for the "${locale}" locale.`);
|
|
250
|
+
}
|
|
251
|
+
return { document: indexHtml.server, nonce: indexHtml.nonce };
|
|
235
252
|
}, _PrerenderPlugin_resolveZonePackage = function _PrerenderPlugin_resolveZonePackage(workspaceRoot) {
|
|
236
253
|
if (tslib_1.__classPrivateFieldGet(this, _PrerenderPlugin__options, "f").zoneless)
|
|
237
254
|
return false;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Compiler, RspackPluginInstance } from '@rspack/core';
|
|
2
|
+
import type { SharedServerRenderingInputs } from './index-html-plugin';
|
|
3
|
+
/**
|
|
4
|
+
* Emits the files the application engine reads from the server output (see
|
|
5
|
+
* `createServerAssets` and `readCriticalCss`).
|
|
6
|
+
*/
|
|
7
|
+
export declare class ServerAssetsPlugin implements RspackPluginInstance {
|
|
8
|
+
private readonly serverRenderingInputs;
|
|
9
|
+
private readonly usesCriticalCssPlans;
|
|
10
|
+
constructor(serverRenderingInputs: SharedServerRenderingInputs, usesCriticalCssPlans: boolean);
|
|
11
|
+
apply(compiler: Compiler): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=server-assets-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-assets-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/server-assets-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAMnE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAIvE;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,oBAAoB;IAE3D,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IACtC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAFvC,YACmB,qBAAqB,EAAE,2BAA2B,EAClD,oBAAoB,EAAE,OAAO,EAC5C;IAEJ,KAAK,CAAC,QAAQ,EAAE,QAAQ,QAqCvB;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerAssetsPlugin = void 0;
|
|
4
|
+
const server_assets_1 = require("../ssr/server-assets");
|
|
5
|
+
const PLUGIN_NAME = 'ServerAssetsPlugin';
|
|
6
|
+
/**
|
|
7
|
+
* Emits the files the application engine reads from the server output (see
|
|
8
|
+
* `createServerAssets` and `readCriticalCss`).
|
|
9
|
+
*/
|
|
10
|
+
class ServerAssetsPlugin {
|
|
11
|
+
constructor(serverRenderingInputs, usesCriticalCssPlans) {
|
|
12
|
+
this.serverRenderingInputs = serverRenderingInputs;
|
|
13
|
+
this.usesCriticalCssPlans = usesCriticalCssPlans;
|
|
14
|
+
}
|
|
15
|
+
apply(compiler) {
|
|
16
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
17
|
+
compilation.hooks.processAssets.tap({
|
|
18
|
+
name: PLUGIN_NAME,
|
|
19
|
+
stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
20
|
+
}, () => {
|
|
21
|
+
const inputs = this.serverRenderingInputs.current;
|
|
22
|
+
// The engine is only wired up without locale inlining.
|
|
23
|
+
const indexHtml = inputs?.indexHtml.get('');
|
|
24
|
+
if (!indexHtml) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const { RawSource } = compiler.rspack.sources;
|
|
28
|
+
compilation.emitAsset(server_assets_1.INDEX_SERVER_HTML, new RawSource(indexHtml.server));
|
|
29
|
+
compilation.emitAsset(server_assets_1.INDEX_CSR_HTML, new RawSource(indexHtml.csr));
|
|
30
|
+
if (this.usesCriticalCssPlans) {
|
|
31
|
+
compilation.emitAsset(server_assets_1.CRITICAL_CSS_FILE, new RawSource(JSON.stringify({
|
|
32
|
+
criticalCssPlans: inputs.criticalCssPlans?.length
|
|
33
|
+
? inputs.criticalCssPlans
|
|
34
|
+
: undefined,
|
|
35
|
+
nonce: indexHtml.nonce,
|
|
36
|
+
})));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.ServerAssetsPlugin = ServerAssetsPlugin;
|
|
@@ -5,8 +5,19 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
|
+
import { type CriticalCssPlan } from '../../utils/beasties';
|
|
8
9
|
export interface RenderOptions {
|
|
10
|
+
/** The server index html the route renders into. */
|
|
11
|
+
document: string;
|
|
12
|
+
/** The `ngCspNonce` attribute value of the document. */
|
|
13
|
+
nonce: string | undefined;
|
|
14
|
+
/** The browser index file name, which prerendering "/" replaces. */
|
|
9
15
|
indexFile: string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the build emits `index.original.html`, which prerendering "/"
|
|
18
|
+
* must then not replace with the browser index.
|
|
19
|
+
*/
|
|
20
|
+
emitsOriginalIndex: boolean;
|
|
10
21
|
deployUrl: string;
|
|
11
22
|
inlineCriticalCss: boolean;
|
|
12
23
|
minifyCss: boolean;
|
|
@@ -14,6 +25,18 @@ export interface RenderOptions {
|
|
|
14
25
|
serverBundlePath: string;
|
|
15
26
|
route: string;
|
|
16
27
|
}
|
|
28
|
+
export interface RenderWorkerData {
|
|
29
|
+
/**
|
|
30
|
+
* The zone.js package loaded during worker initialization, or `false` for
|
|
31
|
+
* zoneless applications.
|
|
32
|
+
*/
|
|
33
|
+
zonePackage: string | false;
|
|
34
|
+
/**
|
|
35
|
+
* Set when critical CSS is inlined from compiled plans, which
|
|
36
|
+
* `@angular/build` >= 22.2 does.
|
|
37
|
+
*/
|
|
38
|
+
criticalCssPlans: CriticalCssPlan[] | undefined;
|
|
39
|
+
}
|
|
17
40
|
export interface RenderResult {
|
|
18
41
|
errors?: string[];
|
|
19
42
|
warnings?: string[];
|
|
@@ -21,7 +44,7 @@ export interface RenderResult {
|
|
|
21
44
|
/**
|
|
22
45
|
* Renders each route in routes and writes them to <outputPath>/<route>/index.html.
|
|
23
46
|
*/
|
|
24
|
-
declare function render({ indexFile, deployUrl, minifyCss, outputPath, serverBundlePath, route, inlineCriticalCss, }: RenderOptions): Promise<RenderResult>;
|
|
47
|
+
declare function render({ document, nonce, indexFile, emitsOriginalIndex, deployUrl, minifyCss, outputPath, serverBundlePath, route, inlineCriticalCss, }: RenderOptions): Promise<RenderResult>;
|
|
25
48
|
/**
|
|
26
49
|
* The default export will be the promise returned by the initialize function.
|
|
27
50
|
* This is awaited by piscina prior to using the Worker.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-worker.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/tools/render-worker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"render-worker.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/tools/render-worker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,oEAAoE;IACpE,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,kBAAkB,EAAE,OAAO,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC;IAC5B;;;OAGG;IACH,gBAAgB,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;CACjD;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAiHD;;GAEG;AACH,iBAAe,MAAM,CAAC,EACpB,QAAQ,EACR,KAAK,EACL,SAAS,EACT,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,iBAAiB,GAClB,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAgGvC;AAuBD;;;GAGG"}
|
|
@@ -12,15 +12,51 @@ const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
|
|
|
12
12
|
const fs = tslib_1.__importStar(require("node:fs"));
|
|
13
13
|
const path = tslib_1.__importStar(require("node:path"));
|
|
14
14
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
15
|
+
const beasties_1 = require("../../utils/beasties");
|
|
16
|
+
// The declarations are those of the installed @angular/build, which no
|
|
17
|
+
// longer export the processor, so its presence is checked at runtime.
|
|
18
|
+
function hasInlineCriticalCssProcessor(angularBuildPrivate) {
|
|
19
|
+
return 'InlineCriticalCssProcessor' in angularBuildPrivate;
|
|
20
|
+
}
|
|
21
|
+
async function processCriticalCss(html, outputPath, deployUrl, minify) {
|
|
22
|
+
const angularBuildPrivate = await import('@angular/build/private');
|
|
23
|
+
(0, node_assert_1.default)(hasInlineCriticalCssProcessor(angularBuildPrivate), 'The installed "@angular/build" requires compiled critical CSS plans.');
|
|
24
|
+
const { InlineCriticalCssProcessor } = angularBuildPrivate;
|
|
25
|
+
return new InlineCriticalCssProcessor({ deployUrl, minify }).process(html, {
|
|
26
|
+
outputPath,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const { zonePackage, criticalCssPlans } = node_worker_threads_1.workerData;
|
|
30
|
+
let criticalCssProcessor;
|
|
31
|
+
/** The warnings of the processor's current run. */
|
|
32
|
+
let criticalCssWarnings = [];
|
|
15
33
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
34
|
+
* Inlines critical CSS the way `@angular/ssr` >= 22.2 does when rendering,
|
|
35
|
+
* from the plans `@angular/build` compiled.
|
|
18
36
|
*/
|
|
19
|
-
|
|
37
|
+
async function inlineCriticalCssFromPlans(html, plans, nonce) {
|
|
38
|
+
criticalCssProcessor ??= (await (0, beasties_1.loadAngularBuildBeasties)('runtime')).createProcessor(plans, {
|
|
39
|
+
preload: 'media-script',
|
|
40
|
+
preloadFonts: true,
|
|
41
|
+
inlineFonts: true,
|
|
42
|
+
noscriptFallback: true,
|
|
43
|
+
cache: true,
|
|
44
|
+
logger: { warn: (message) => criticalCssWarnings.push(message) },
|
|
45
|
+
});
|
|
46
|
+
const warnings = (criticalCssWarnings = []);
|
|
47
|
+
try {
|
|
48
|
+
return { content: criticalCssProcessor.process(html, { nonce }), warnings };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// Like @angular/ssr, a failure leaves the page without critical CSS.
|
|
52
|
+
warnings.push(`An error occurred while inlining critical CSS: ${error instanceof Error ? error.message : error}`);
|
|
53
|
+
return { content: html, warnings };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
20
56
|
/**
|
|
21
57
|
* Renders each route in routes and writes them to <outputPath>/<route>/index.html.
|
|
22
58
|
*/
|
|
23
|
-
async function render({ indexFile, deployUrl, minifyCss, outputPath, serverBundlePath, route, inlineCriticalCss, }) {
|
|
59
|
+
async function render({ document, nonce, indexFile, emitsOriginalIndex, deployUrl, minifyCss, outputPath, serverBundlePath, route, inlineCriticalCss, }) {
|
|
24
60
|
const result = {};
|
|
25
61
|
const browserIndexOutputPath = path.join(outputPath, indexFile);
|
|
26
62
|
const outputFolderPath = path.join(outputPath, route);
|
|
@@ -30,11 +66,6 @@ async function render({ indexFile, deployUrl, minifyCss, outputPath, serverBundl
|
|
|
30
66
|
const { ɵSERVER_CONTEXT, AppServerModule, renderModule, renderApplication, default: defaultExport, __ngRspackMainServerBootstrap, } = require(serverBundlePath);
|
|
31
67
|
const bootstrapAppFn = defaultExport ?? __ngRspackMainServerBootstrap;
|
|
32
68
|
(0, node_assert_1.default)(ɵSERVER_CONTEXT, `ɵSERVER_CONTEXT was not exported from: ${serverBundlePath}.`);
|
|
33
|
-
const indexBaseName = fs.existsSync(path.join(outputPath, 'index.original.html'))
|
|
34
|
-
? 'index.original.html'
|
|
35
|
-
: indexFile;
|
|
36
|
-
const browserIndexInputPath = path.join(outputPath, indexBaseName);
|
|
37
|
-
const document = await fs.promises.readFile(browserIndexInputPath, 'utf8');
|
|
38
69
|
const platformProviders = [
|
|
39
70
|
{
|
|
40
71
|
provide: ɵSERVER_CONTEXT,
|
|
@@ -61,21 +92,19 @@ async function render({ indexFile, deployUrl, minifyCss, outputPath, serverBundl
|
|
|
61
92
|
extraProviders: platformProviders,
|
|
62
93
|
});
|
|
63
94
|
}
|
|
64
|
-
if (inlineCriticalCss) {
|
|
65
|
-
const {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const { content, warnings, errors } = await
|
|
71
|
-
outputPath,
|
|
72
|
-
});
|
|
95
|
+
if (inlineCriticalCss && criticalCssPlans) {
|
|
96
|
+
const { content, warnings } = await inlineCriticalCssFromPlans(html, criticalCssPlans, nonce);
|
|
97
|
+
result.warnings = warnings;
|
|
98
|
+
html = content;
|
|
99
|
+
}
|
|
100
|
+
else if (inlineCriticalCss) {
|
|
101
|
+
const { content, warnings, errors } = await processCriticalCss(html, outputPath, deployUrl, minifyCss);
|
|
73
102
|
result.errors = errors;
|
|
74
103
|
result.warnings = warnings;
|
|
75
104
|
html = content;
|
|
76
105
|
}
|
|
77
106
|
// This case happens when we are prerendering "/".
|
|
78
|
-
if (browserIndexOutputPath === outputIndexPath) {
|
|
107
|
+
if (browserIndexOutputPath === outputIndexPath && !emitsOriginalIndex) {
|
|
79
108
|
const browserIndexOutputPathOriginal = path.join(outputPath, 'index.original.html');
|
|
80
109
|
fs.renameSync(browserIndexOutputPath, browserIndexOutputPathOriginal);
|
|
81
110
|
}
|
|
@@ -1,24 +1,40 @@
|
|
|
1
|
+
/** The document server rendering renders into, in the server output. */
|
|
2
|
+
export declare const INDEX_SERVER_HTML = "index.server.html";
|
|
3
|
+
/** The document served for client-rendered routes, in the server output. */
|
|
4
|
+
export declare const INDEX_CSR_HTML = "index.csr.html";
|
|
5
|
+
/**
|
|
6
|
+
* The app manifest's critical CSS fields for `@angular/ssr` >= 22.2, in the
|
|
7
|
+
* server output.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CRITICAL_CSS_FILE = "critical-css.json";
|
|
1
10
|
interface ServerAsset {
|
|
2
11
|
text: () => Promise<string>;
|
|
3
12
|
}
|
|
4
13
|
/**
|
|
5
|
-
* Builds the `assets` table of the Angular app manifest from the
|
|
6
|
-
* output
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* contents under output hashing).
|
|
14
|
+
* Builds the `assets` table of the Angular app manifest from the build
|
|
15
|
+
* output. The esbuild application builder inlines these assets into the
|
|
16
|
+
* server output at build time; here only directory listings and file stats
|
|
17
|
+
* are read when the server process starts and contents are read lazily, so a
|
|
18
|
+
* restarted process always serves the current build output and rebuilds never
|
|
19
|
+
* have to invalidate the SSR entry module (whose injected code would
|
|
20
|
+
* otherwise embed stale index contents under output hashing).
|
|
13
21
|
*
|
|
14
|
-
* The
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
22
|
+
* The index documents come from the server output. Top-level stylesheets of
|
|
23
|
+
* the browser output are included only when `inlineCriticalCss` is set: the
|
|
24
|
+
* inliner of `@angular/ssr` < 22.2, which fetches them by file name, is their
|
|
25
|
+
* only consumer.
|
|
18
26
|
*
|
|
19
27
|
* This module is bundled into the user's server bundle, so it must only
|
|
20
28
|
* import node builtins.
|
|
21
29
|
*/
|
|
22
|
-
export declare function
|
|
30
|
+
export declare function createServerAssets(serverOutputPath: string, browserOutputPath: string, inlineCriticalCss: boolean): Record<string, ServerAsset>;
|
|
31
|
+
/**
|
|
32
|
+
* Reads the `criticalCssPlans` and `nonce` app manifest fields, which
|
|
33
|
+
* `@angular/ssr` >= 22.2 inlines critical CSS with.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readCriticalCss(serverOutputPath: string): {
|
|
36
|
+
criticalCssPlans?: unknown[];
|
|
37
|
+
nonce?: string;
|
|
38
|
+
};
|
|
23
39
|
export {};
|
|
24
40
|
//# sourceMappingURL=server-assets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-assets.d.ts","sourceRoot":"","sources":["../../../src/lib/ssr/server-assets.ts"],"names":[],"mappings":"AAIA,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED
|
|
1
|
+
{"version":3,"file":"server-assets.d.ts","sourceRoot":"","sources":["../../../src/lib/ssr/server-assets.ts"],"names":[],"mappings":"AAIA,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AACrD,4EAA4E;AAC5E,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAChC,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,MAAM,EACzB,iBAAiB,EAAE,OAAO,GACzB,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CA4B7B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,MAAM,GAAG;IACzD,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAaA"}
|