@angular/build 19.0.0-next.0 → 19.0.0-next.10
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/LICENSE +5 -5
- package/package.json +20 -16
- package/src/builders/application/build-action.js +9 -9
- package/src/builders/application/chunk-optimizer.js +1 -4
- package/src/builders/application/execute-build.js +19 -2
- package/src/builders/application/execute-post-bundle.d.ts +2 -2
- package/src/builders/application/execute-post-bundle.js +58 -20
- package/src/builders/application/i18n.d.ts +2 -2
- package/src/builders/application/i18n.js +6 -16
- package/src/builders/application/index.js +8 -5
- package/src/builders/application/options.d.ts +36 -1
- package/src/builders/application/options.js +60 -3
- package/src/builders/application/schema.d.ts +15 -0
- package/src/builders/application/schema.js +11 -1
- package/src/builders/application/schema.json +5 -0
- package/src/builders/application/setup-bundling.js +12 -9
- package/src/builders/dev-server/internal.d.ts +0 -1
- package/src/builders/dev-server/internal.js +1 -3
- package/src/builders/dev-server/vite-server.d.ts +8 -2
- package/src/builders/dev-server/vite-server.js +111 -56
- package/src/builders/extract-i18n/application-extraction.js +7 -3
- package/src/tools/angular/angular-host.d.ts +2 -1
- package/src/tools/angular/angular-host.js +20 -1
- package/src/tools/angular/compilation/angular-compilation.d.ts +1 -0
- package/src/tools/angular/compilation/aot-compilation.d.ts +1 -0
- package/src/tools/angular/compilation/aot-compilation.js +9 -1
- package/src/tools/angular/compilation/jit-compilation.js +2 -1
- package/src/tools/angular/compilation/parallel-compilation.d.ts +2 -1
- package/src/tools/angular/compilation/parallel-compilation.js +2 -10
- package/src/tools/angular/compilation/parallel-worker.d.ts +1 -0
- package/src/tools/angular/compilation/parallel-worker.js +2 -1
- package/src/tools/babel/plugins/add-code-coverage.d.ts +14 -0
- package/src/tools/babel/plugins/add-code-coverage.js +44 -0
- package/src/tools/babel/plugins/types.d.ts +20 -0
- package/src/tools/esbuild/angular/compiler-plugin.d.ts +2 -0
- package/src/tools/esbuild/angular/compiler-plugin.js +46 -4
- package/src/tools/esbuild/angular/component-stylesheets.d.ts +8 -3
- package/src/tools/esbuild/angular/component-stylesheets.js +46 -11
- package/src/tools/esbuild/angular/file-reference-tracker.d.ts +1 -1
- package/src/tools/esbuild/application-code-bundle.d.ts +2 -6
- package/src/tools/esbuild/application-code-bundle.js +208 -92
- package/src/tools/esbuild/budget-stats.js +1 -1
- package/src/tools/esbuild/bundler-context.d.ts +4 -3
- package/src/tools/esbuild/bundler-context.js +21 -13
- package/src/tools/esbuild/bundler-execution-result.d.ts +5 -2
- package/src/tools/esbuild/bundler-execution-result.js +7 -3
- package/src/tools/esbuild/cache.d.ts +6 -1
- package/src/tools/esbuild/cache.js +7 -0
- package/src/tools/esbuild/compiler-plugin-options.js +3 -1
- package/src/tools/esbuild/i18n-inliner.js +4 -4
- package/src/tools/esbuild/javascript-transformer-worker.d.ts +1 -0
- package/src/tools/esbuild/javascript-transformer-worker.js +5 -1
- package/src/tools/esbuild/javascript-transformer.d.ts +2 -2
- package/src/tools/esbuild/javascript-transformer.js +7 -12
- package/src/tools/esbuild/utils.d.ts +9 -0
- package/src/tools/esbuild/utils.js +21 -3
- package/src/tools/sass/sass-service.js +11 -13
- package/src/tools/sass/worker.d.ts +13 -32
- package/src/tools/sass/worker.js +1 -0
- package/src/tools/vite/middlewares/assets-middleware.d.ts +1 -1
- package/src/tools/vite/middlewares/assets-middleware.js +43 -4
- package/src/tools/vite/middlewares/headers-middleware.d.ts +19 -0
- package/src/tools/vite/middlewares/headers-middleware.js +34 -0
- package/src/tools/vite/middlewares/html-fallback-middleware.d.ts +1 -1
- package/src/tools/vite/middlewares/html-fallback-middleware.js +23 -7
- package/src/tools/vite/middlewares/index-html-middleware.js +1 -2
- package/src/tools/vite/middlewares/index.d.ts +2 -1
- package/src/tools/vite/middlewares/index.js +5 -2
- package/src/tools/vite/middlewares/ssr-middleware.d.ts +2 -4
- package/src/tools/vite/middlewares/ssr-middleware.js +75 -43
- package/src/tools/vite/plugins/angular-memory-plugin.d.ts +16 -0
- package/src/tools/vite/{angular-memory-plugin.js → plugins/angular-memory-plugin.js} +19 -40
- package/src/tools/vite/{i18n-locale-plugin.d.ts → plugins/i18n-locale-plugin.d.ts} +0 -4
- package/src/tools/vite/{i18n-locale-plugin.js → plugins/i18n-locale-plugin.js} +2 -3
- package/src/tools/vite/plugins/index.d.ts +12 -0
- package/src/tools/vite/plugins/index.js +21 -0
- package/src/tools/vite/plugins/setup-middlewares-plugin.d.ts +41 -0
- package/src/tools/vite/plugins/setup-middlewares-plugin.js +62 -0
- package/src/{utils/server-rendering/main-bundle-exports.js → tools/vite/plugins/ssr-transform-plugin.d.ts} +2 -2
- package/src/tools/vite/plugins/ssr-transform-plugin.js +38 -0
- package/src/tools/vite/utils.d.ts +0 -3
- package/src/tools/vite/utils.js +0 -12
- package/src/typings.d.ts +26 -0
- package/src/utils/environment-options.d.ts +2 -0
- package/src/utils/environment-options.js +5 -1
- package/src/utils/index-file/index-html-generator.js +5 -0
- package/src/utils/index-file/inline-critical-css.js +43 -33
- package/src/utils/index-file/ngcm-attribute.d.ts +15 -0
- package/src/utils/index-file/ngcm-attribute.js +37 -0
- package/src/utils/index-file/valid-self-closing-tags.js +28 -0
- package/src/utils/normalize-cache.js +1 -1
- package/src/utils/server-rendering/fetch-patch.d.ts +1 -1
- package/src/utils/server-rendering/fetch-patch.js +5 -6
- package/src/utils/server-rendering/launch-server.d.ts +14 -0
- package/src/utils/server-rendering/launch-server.js +63 -0
- package/src/utils/server-rendering/load-esm-from-memory.d.ts +18 -2
- package/src/utils/server-rendering/manifest.d.ts +50 -0
- package/src/utils/server-rendering/manifest.js +126 -0
- package/src/utils/server-rendering/models.d.ts +27 -0
- package/src/utils/server-rendering/models.js +22 -0
- package/src/utils/server-rendering/prerender.d.ts +26 -10
- package/src/utils/server-rendering/prerender.js +126 -67
- package/src/utils/server-rendering/render-worker.d.ts +9 -8
- package/src/utils/server-rendering/render-worker.js +19 -14
- package/src/utils/server-rendering/routes-extractor-worker.d.ts +6 -10
- package/src/utils/server-rendering/routes-extractor-worker.js +16 -33
- package/src/utils/server-rendering/utils.d.ts +11 -0
- package/src/utils/server-rendering/utils.js +17 -0
- package/src/utils/worker-pool.d.ts +12 -0
- package/src/utils/worker-pool.js +43 -0
- package/src/tools/vite/angular-memory-plugin.d.ts +0 -21
- package/src/utils/server-rendering/main-bundle-exports.d.ts +0 -27
- package/src/utils/server-rendering/render-page.d.ts +0 -26
- package/src/utils/server-rendering/render-page.js +0 -114
- /package/src/tools/vite/{id-prefix-plugin.d.ts → plugins/id-prefix-plugin.d.ts} +0 -0
- /package/src/tools/vite/{id-prefix-plugin.js → plugins/id-prefix-plugin.js} +0 -0
|
@@ -7,51 +7,83 @@
|
|
|
7
7
|
* found in the LICENSE file at https://angular.dev/license
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// Skip if path is like a file.
|
|
20
|
-
// NOTE: We use a mime type lookup to mitigate against matching requests like: /browse/pl.0ef59752c0cd457dbf1391f08cbd936f
|
|
21
|
-
(0, utils_1.lookupMimeTypeFromRequest)(url)) {
|
|
22
|
-
next();
|
|
23
|
-
return;
|
|
10
|
+
exports.createAngularSsrInternalMiddleware = createAngularSsrInternalMiddleware;
|
|
11
|
+
exports.createAngularSsrExternalMiddleware = createAngularSsrExternalMiddleware;
|
|
12
|
+
const load_esm_1 = require("../../../utils/load-esm");
|
|
13
|
+
const utils_1 = require("../../../utils/server-rendering/utils");
|
|
14
|
+
function createAngularSsrInternalMiddleware(server, indexHtmlTransformer) {
|
|
15
|
+
let cachedAngularServerApp;
|
|
16
|
+
return function angularSsrMiddleware(req, res, next) {
|
|
17
|
+
if (req.url === undefined) {
|
|
18
|
+
return next();
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
(async () => {
|
|
21
|
+
// Load the compiler because `@angular/ssr/node` depends on `@angular/` packages,
|
|
22
|
+
// which must be processed by the runtime linker, even if they are not used.
|
|
23
|
+
await (0, load_esm_1.loadEsmModule)('@angular/compiler');
|
|
24
|
+
const { writeResponseToNodeResponse, createWebRequestFromNodeRequest } = await (0, load_esm_1.loadEsmModule)('@angular/ssr/node');
|
|
25
|
+
const { ɵgetOrCreateAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs'));
|
|
26
|
+
const angularServerApp = ɵgetOrCreateAngularServerApp();
|
|
27
|
+
// Only Add the transform hook only if it's a different instance.
|
|
28
|
+
if (cachedAngularServerApp !== angularServerApp) {
|
|
29
|
+
angularServerApp.hooks.on('html:transform:pre', async ({ html, url }) => {
|
|
30
|
+
const processedHtml = await server.transformIndexHtml(url.pathname, html);
|
|
31
|
+
return indexHtmlTransformer?.(processedHtml) ?? processedHtml;
|
|
32
|
+
});
|
|
33
|
+
cachedAngularServerApp = angularServerApp;
|
|
37
34
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
route: new URL(req.originalUrl ?? '/', baseUrl).toString(),
|
|
41
|
-
serverContext: 'ssr',
|
|
42
|
-
loadBundle: (uri) =>
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
server.ssrLoadModule(uri.slice(1)),
|
|
45
|
-
// Files here are only needed for critical CSS inlining.
|
|
46
|
-
outputFiles: {},
|
|
47
|
-
// TODO: add support for critical css inlining.
|
|
48
|
-
inlineCriticalCss: false,
|
|
35
|
+
const webReq = new Request(createWebRequestFromNodeRequest(req), {
|
|
36
|
+
signal: AbortSignal.timeout(30_000),
|
|
49
37
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
38
|
+
const webRes = await angularServerApp.render(webReq);
|
|
39
|
+
if (!webRes) {
|
|
40
|
+
return next();
|
|
41
|
+
}
|
|
42
|
+
return writeResponseToNodeResponse(webRes, res);
|
|
43
|
+
})().catch(next);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function createAngularSsrExternalMiddleware(server, indexHtmlTransformer) {
|
|
47
|
+
let fallbackWarningShown = false;
|
|
48
|
+
let cachedAngularAppEngine;
|
|
49
|
+
let angularSsrInternalMiddleware;
|
|
50
|
+
// Load the compiler because `@angular/ssr/node` depends on `@angular/` packages,
|
|
51
|
+
// which must be processed by the runtime linker, even if they are not used.
|
|
52
|
+
await (0, load_esm_1.loadEsmModule)('@angular/compiler');
|
|
53
|
+
const { createWebRequestFromNodeRequest, writeResponseToNodeResponse } = await (0, load_esm_1.loadEsmModule)('@angular/ssr/node');
|
|
54
|
+
return function angularSsrExternalMiddleware(req, res, next) {
|
|
55
|
+
(async () => {
|
|
56
|
+
const { default: handler, AngularAppEngine } = (await server.ssrLoadModule('./server.mjs'));
|
|
57
|
+
if (!(0, utils_1.isSsrNodeRequestHandler)(handler) && !(0, utils_1.isSsrRequestHandler)(handler)) {
|
|
58
|
+
if (!fallbackWarningShown) {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.warn(`The default export in 'server.ts' does not provide a Node.js request handler. ` +
|
|
61
|
+
'Using the internal SSR middleware instead.');
|
|
62
|
+
fallbackWarningShown = true;
|
|
63
|
+
}
|
|
64
|
+
angularSsrInternalMiddleware ??= createAngularSsrInternalMiddleware(server, indexHtmlTransformer);
|
|
65
|
+
angularSsrInternalMiddleware(req, res, next);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (cachedAngularAppEngine !== AngularAppEngine) {
|
|
69
|
+
AngularAppEngine.ɵhooks.on('html:transform:pre', async ({ html, url }) => {
|
|
70
|
+
const processedHtml = await server.transformIndexHtml(url.pathname, html);
|
|
71
|
+
return indexHtmlTransformer?.(processedHtml) ?? processedHtml;
|
|
72
|
+
});
|
|
73
|
+
cachedAngularAppEngine = AngularAppEngine;
|
|
74
|
+
}
|
|
75
|
+
// Forward the request to the middleware in server.ts
|
|
76
|
+
if ((0, utils_1.isSsrNodeRequestHandler)(handler)) {
|
|
77
|
+
await handler(req, res, next);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const webRes = await handler(createWebRequestFromNodeRequest(req));
|
|
81
|
+
if (!webRes) {
|
|
82
|
+
next();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
await writeResponseToNodeResponse(webRes, res);
|
|
86
|
+
}
|
|
87
|
+
})().catch(next);
|
|
56
88
|
};
|
|
57
89
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'vite';
|
|
9
|
+
import { AngularMemoryOutputFiles } from '../utils';
|
|
10
|
+
interface AngularMemoryPluginOptions {
|
|
11
|
+
virtualProjectRoot: string;
|
|
12
|
+
outputFiles: AngularMemoryOutputFiles;
|
|
13
|
+
external?: string[];
|
|
14
|
+
}
|
|
15
|
+
export declare function createAngularMemoryPlugin(options: AngularMemoryPluginOptions): Promise<Plugin>;
|
|
16
|
+
export {};
|
|
@@ -11,13 +11,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.createAngularMemoryPlugin = createAngularMemoryPlugin;
|
|
14
|
-
const remapping_1 = __importDefault(require("@ampproject/remapping"));
|
|
15
14
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
16
15
|
const promises_1 = require("node:fs/promises");
|
|
17
16
|
const node_path_1 = require("node:path");
|
|
18
|
-
const
|
|
19
|
-
function createAngularMemoryPlugin(options) {
|
|
20
|
-
const {
|
|
17
|
+
const load_esm_1 = require("../../../utils/load-esm");
|
|
18
|
+
async function createAngularMemoryPlugin(options) {
|
|
19
|
+
const { virtualProjectRoot, outputFiles, external } = options;
|
|
20
|
+
const { normalizePath } = await (0, load_esm_1.loadEsmModule)('vite');
|
|
21
|
+
// See: https://github.com/vitejs/vite/blob/a34a73a3ad8feeacc98632c0f4c643b6820bbfda/packages/vite/src/node/server/pluginContainer.ts#L331-L334
|
|
22
|
+
const defaultImporter = (0, node_path_1.join)(virtualProjectRoot, 'index.html');
|
|
21
23
|
return {
|
|
22
24
|
name: 'vite:angular-memory',
|
|
23
25
|
// Ensures plugin hooks run before built-in Vite hooks
|
|
@@ -29,11 +31,19 @@ function createAngularMemoryPlugin(options) {
|
|
|
29
31
|
// `/@id/${source}` but is currently closer to a raw external than a resolved file path.
|
|
30
32
|
return source;
|
|
31
33
|
}
|
|
32
|
-
if (importer
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
if (importer) {
|
|
35
|
+
let normalizedSource;
|
|
36
|
+
if (source[0] === '.' && normalizePath(importer).startsWith(virtualProjectRoot)) {
|
|
37
|
+
// Remove query if present
|
|
38
|
+
const [importerFile] = importer.split('?', 1);
|
|
39
|
+
normalizedSource = (0, node_path_1.join)((0, node_path_1.dirname)((0, node_path_1.relative)(virtualProjectRoot, importerFile)), source);
|
|
40
|
+
}
|
|
41
|
+
else if (source[0] === '/' && importer === defaultImporter) {
|
|
42
|
+
normalizedSource = (0, node_path_1.basename)(source);
|
|
43
|
+
}
|
|
44
|
+
if (normalizedSource) {
|
|
45
|
+
source = '/' + normalizePath(normalizedSource);
|
|
46
|
+
}
|
|
37
47
|
}
|
|
38
48
|
const [file] = source.split('?', 1);
|
|
39
49
|
if (outputFiles.has(file)) {
|
|
@@ -58,37 +68,6 @@ function createAngularMemoryPlugin(options) {
|
|
|
58
68
|
map: mapContents && Buffer.from(mapContents).toString('utf-8'),
|
|
59
69
|
};
|
|
60
70
|
},
|
|
61
|
-
// eslint-disable-next-line max-lines-per-function
|
|
62
|
-
configureServer(server) {
|
|
63
|
-
const originalssrTransform = server.ssrTransform;
|
|
64
|
-
server.ssrTransform = async (code, map, url, originalCode) => {
|
|
65
|
-
const result = await originalssrTransform(code, null, url, originalCode);
|
|
66
|
-
if (!result || !result.map || !map) {
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
const remappedMap = (0, remapping_1.default)([result.map, map], () => null);
|
|
70
|
-
// Set the sourcemap root to the workspace root. This is needed since we set a virtual path as root.
|
|
71
|
-
remappedMap.sourceRoot = normalizePath(workspaceRoot) + '/';
|
|
72
|
-
return {
|
|
73
|
-
...result,
|
|
74
|
-
map: remappedMap,
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
// Assets and resources get handled first
|
|
78
|
-
server.middlewares.use((0, middlewares_1.createAngularAssetsMiddleware)(server, assets, outputFiles));
|
|
79
|
-
if (extensionMiddleware?.length) {
|
|
80
|
-
extensionMiddleware.forEach((middleware) => server.middlewares.use(middleware));
|
|
81
|
-
}
|
|
82
|
-
// Returning a function, installs middleware after the main transform middleware but
|
|
83
|
-
// before the built-in HTML middleware
|
|
84
|
-
return () => {
|
|
85
|
-
server.middlewares.use(middlewares_1.angularHtmlFallbackMiddleware);
|
|
86
|
-
if (ssr) {
|
|
87
|
-
server.middlewares.use((0, middlewares_1.createAngularSSRMiddleware)(server, outputFiles, indexHtmlTransformer));
|
|
88
|
-
}
|
|
89
|
-
server.middlewares.use((0, middlewares_1.createAngularIndexHtmlMiddleware)(server, outputFiles, indexHtmlTransformer));
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
71
|
};
|
|
93
72
|
}
|
|
94
73
|
/**
|
|
@@ -6,10 +6,6 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
8
|
import type { Plugin } from 'vite';
|
|
9
|
-
/**
|
|
10
|
-
* The base module location used to search for locale specific data.
|
|
11
|
-
*/
|
|
12
|
-
export declare const LOCALE_DATA_BASE_MODULE = "@angular/common/locales/global";
|
|
13
9
|
/**
|
|
14
10
|
* Creates a Vite plugin that resolves Angular locale data files from `@angular/common`.
|
|
15
11
|
*
|
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
* found in the LICENSE file at https://angular.dev/license
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.LOCALE_DATA_BASE_MODULE = void 0;
|
|
11
10
|
exports.createAngularLocaleDataPlugin = createAngularLocaleDataPlugin;
|
|
12
11
|
/**
|
|
13
12
|
* The base module location used to search for locale specific data.
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
const LOCALE_DATA_BASE_MODULE = '@angular/common/locales/global';
|
|
16
15
|
/**
|
|
17
16
|
* Creates a Vite plugin that resolves Angular locale data files from `@angular/common`.
|
|
18
17
|
*
|
|
@@ -32,7 +31,7 @@ function createAngularLocaleDataPlugin() {
|
|
|
32
31
|
let partialLocale = originalLocale.replace(/-x(-[a-zA-Z0-9]{1,8})+$/, '');
|
|
33
32
|
let exact = true;
|
|
34
33
|
while (partialLocale) {
|
|
35
|
-
const potentialPath = `${
|
|
34
|
+
const potentialPath = `${LOCALE_DATA_BASE_MODULE}/${partialLocale}`;
|
|
36
35
|
const result = await this.resolve(potentialPath);
|
|
37
36
|
if (result) {
|
|
38
37
|
if (!exact) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
export { createAngularMemoryPlugin } from './angular-memory-plugin';
|
|
9
|
+
export { createAngularLocaleDataPlugin } from './i18n-locale-plugin';
|
|
10
|
+
export { createRemoveIdPrefixPlugin } from './id-prefix-plugin';
|
|
11
|
+
export { createAngularSetupMiddlewaresPlugin, ServerSsrMode } from './setup-middlewares-plugin';
|
|
12
|
+
export { createAngularSsrTransformPlugin } from './ssr-transform-plugin';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createAngularSsrTransformPlugin = exports.ServerSsrMode = exports.createAngularSetupMiddlewaresPlugin = exports.createRemoveIdPrefixPlugin = exports.createAngularLocaleDataPlugin = exports.createAngularMemoryPlugin = void 0;
|
|
11
|
+
var angular_memory_plugin_1 = require("./angular-memory-plugin");
|
|
12
|
+
Object.defineProperty(exports, "createAngularMemoryPlugin", { enumerable: true, get: function () { return angular_memory_plugin_1.createAngularMemoryPlugin; } });
|
|
13
|
+
var i18n_locale_plugin_1 = require("./i18n-locale-plugin");
|
|
14
|
+
Object.defineProperty(exports, "createAngularLocaleDataPlugin", { enumerable: true, get: function () { return i18n_locale_plugin_1.createAngularLocaleDataPlugin; } });
|
|
15
|
+
var id_prefix_plugin_1 = require("./id-prefix-plugin");
|
|
16
|
+
Object.defineProperty(exports, "createRemoveIdPrefixPlugin", { enumerable: true, get: function () { return id_prefix_plugin_1.createRemoveIdPrefixPlugin; } });
|
|
17
|
+
var setup_middlewares_plugin_1 = require("./setup-middlewares-plugin");
|
|
18
|
+
Object.defineProperty(exports, "createAngularSetupMiddlewaresPlugin", { enumerable: true, get: function () { return setup_middlewares_plugin_1.createAngularSetupMiddlewaresPlugin; } });
|
|
19
|
+
Object.defineProperty(exports, "ServerSsrMode", { enumerable: true, get: function () { return setup_middlewares_plugin_1.ServerSsrMode; } });
|
|
20
|
+
var ssr_transform_plugin_1 = require("./ssr-transform-plugin");
|
|
21
|
+
Object.defineProperty(exports, "createAngularSsrTransformPlugin", { enumerable: true, get: function () { return ssr_transform_plugin_1.createAngularSsrTransformPlugin; } });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Connect, Plugin } from 'vite';
|
|
9
|
+
import { AngularMemoryOutputFiles } from '../utils';
|
|
10
|
+
export declare enum ServerSsrMode {
|
|
11
|
+
/**
|
|
12
|
+
* No SSR
|
|
13
|
+
*/
|
|
14
|
+
NoSsr = 0,
|
|
15
|
+
/**
|
|
16
|
+
* Internal server-side rendering (SSR) is handled through the built-in middleware.
|
|
17
|
+
*
|
|
18
|
+
* In this mode, the SSR process is managed internally by the dev-server's middleware.
|
|
19
|
+
* The server automatically renders pages on the server without requiring external
|
|
20
|
+
* middleware or additional configuration from the developer.
|
|
21
|
+
*/
|
|
22
|
+
InternalSsrMiddleware = 1,
|
|
23
|
+
/**
|
|
24
|
+
* External server-side rendering (SSR) is handled by a custom middleware defined in server.ts.
|
|
25
|
+
*
|
|
26
|
+
* This mode allows developers to define custom SSR behavior by providing a middleware in the
|
|
27
|
+
* `server.ts` file. It gives more flexibility for handling SSR, such as integrating with other
|
|
28
|
+
* frameworks or customizing the rendering pipeline.
|
|
29
|
+
*/
|
|
30
|
+
ExternalSsrMiddleware = 2
|
|
31
|
+
}
|
|
32
|
+
interface AngularSetupMiddlewaresPluginOptions {
|
|
33
|
+
outputFiles: AngularMemoryOutputFiles;
|
|
34
|
+
assets: Map<string, string>;
|
|
35
|
+
extensionMiddleware?: Connect.NextHandleFunction[];
|
|
36
|
+
indexHtmlTransformer?: (content: string) => Promise<string>;
|
|
37
|
+
usedComponentStyles: Map<string, string[]>;
|
|
38
|
+
ssrMode: ServerSsrMode;
|
|
39
|
+
}
|
|
40
|
+
export declare function createAngularSetupMiddlewaresPlugin(options: AngularSetupMiddlewaresPluginOptions): Plugin;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ServerSsrMode = void 0;
|
|
11
|
+
exports.createAngularSetupMiddlewaresPlugin = createAngularSetupMiddlewaresPlugin;
|
|
12
|
+
const middlewares_1 = require("../middlewares");
|
|
13
|
+
var ServerSsrMode;
|
|
14
|
+
(function (ServerSsrMode) {
|
|
15
|
+
/**
|
|
16
|
+
* No SSR
|
|
17
|
+
*/
|
|
18
|
+
ServerSsrMode[ServerSsrMode["NoSsr"] = 0] = "NoSsr";
|
|
19
|
+
/**
|
|
20
|
+
* Internal server-side rendering (SSR) is handled through the built-in middleware.
|
|
21
|
+
*
|
|
22
|
+
* In this mode, the SSR process is managed internally by the dev-server's middleware.
|
|
23
|
+
* The server automatically renders pages on the server without requiring external
|
|
24
|
+
* middleware or additional configuration from the developer.
|
|
25
|
+
*/
|
|
26
|
+
ServerSsrMode[ServerSsrMode["InternalSsrMiddleware"] = 1] = "InternalSsrMiddleware";
|
|
27
|
+
/**
|
|
28
|
+
* External server-side rendering (SSR) is handled by a custom middleware defined in server.ts.
|
|
29
|
+
*
|
|
30
|
+
* This mode allows developers to define custom SSR behavior by providing a middleware in the
|
|
31
|
+
* `server.ts` file. It gives more flexibility for handling SSR, such as integrating with other
|
|
32
|
+
* frameworks or customizing the rendering pipeline.
|
|
33
|
+
*/
|
|
34
|
+
ServerSsrMode[ServerSsrMode["ExternalSsrMiddleware"] = 2] = "ExternalSsrMiddleware";
|
|
35
|
+
})(ServerSsrMode || (exports.ServerSsrMode = ServerSsrMode = {}));
|
|
36
|
+
function createAngularSetupMiddlewaresPlugin(options) {
|
|
37
|
+
return {
|
|
38
|
+
name: 'vite:angular-setup-middlewares',
|
|
39
|
+
enforce: 'pre',
|
|
40
|
+
configureServer(server) {
|
|
41
|
+
const { indexHtmlTransformer, outputFiles, extensionMiddleware, assets, usedComponentStyles, ssrMode, } = options;
|
|
42
|
+
// Headers, assets and resources get handled first
|
|
43
|
+
server.middlewares.use((0, middlewares_1.createAngularHeadersMiddleware)(server));
|
|
44
|
+
server.middlewares.use((0, middlewares_1.createAngularAssetsMiddleware)(server, assets, outputFiles, usedComponentStyles));
|
|
45
|
+
extensionMiddleware?.forEach((middleware) => server.middlewares.use(middleware));
|
|
46
|
+
// Returning a function, installs middleware after the main transform middleware but
|
|
47
|
+
// before the built-in HTML middleware
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
49
|
+
return async () => {
|
|
50
|
+
if (ssrMode === ServerSsrMode.ExternalSsrMiddleware) {
|
|
51
|
+
server.middlewares.use(await (0, middlewares_1.createAngularSsrExternalMiddleware)(server, indexHtmlTransformer));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (ssrMode === ServerSsrMode.InternalSsrMiddleware) {
|
|
55
|
+
server.middlewares.use((0, middlewares_1.createAngularSsrInternalMiddleware)(server, indexHtmlTransformer));
|
|
56
|
+
}
|
|
57
|
+
server.middlewares.use(middlewares_1.angularHtmlFallbackMiddleware);
|
|
58
|
+
server.middlewares.use((0, middlewares_1.createAngularIndexHtmlMiddleware)(server, outputFiles, indexHtmlTransformer));
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @license
|
|
4
3
|
* Copyright Google LLC All Rights Reserved.
|
|
@@ -6,4 +5,5 @@
|
|
|
6
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
import type { Plugin } from 'vite';
|
|
9
|
+
export declare function createAngularSsrTransformPlugin(workspaceRoot: string): Promise<Plugin>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.createAngularSsrTransformPlugin = createAngularSsrTransformPlugin;
|
|
14
|
+
const remapping_1 = __importDefault(require("@ampproject/remapping"));
|
|
15
|
+
const load_esm_1 = require("../../../utils/load-esm");
|
|
16
|
+
async function createAngularSsrTransformPlugin(workspaceRoot) {
|
|
17
|
+
const { normalizePath } = await (0, load_esm_1.loadEsmModule)('vite');
|
|
18
|
+
return {
|
|
19
|
+
name: 'vite:angular-ssr-transform',
|
|
20
|
+
enforce: 'pre',
|
|
21
|
+
async configureServer(server) {
|
|
22
|
+
const originalssrTransform = server.ssrTransform;
|
|
23
|
+
server.ssrTransform = async (code, map, url, originalCode) => {
|
|
24
|
+
const result = await originalssrTransform(code, null, url, originalCode);
|
|
25
|
+
if (!result || !result.map || !map) {
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
const remappedMap = (0, remapping_1.default)([result.map, map], () => null);
|
|
29
|
+
// Set the sourcemap root to the workspace root. This is needed since we set a virtual path as root.
|
|
30
|
+
remappedMap.sourceRoot = normalizePath(workspaceRoot) + '/';
|
|
31
|
+
return {
|
|
32
|
+
...result,
|
|
33
|
+
map: remappedMap,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -5,12 +5,9 @@
|
|
|
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 { IncomingMessage, ServerResponse } from 'node:http';
|
|
9
|
-
import type { ViteDevServer } from 'vite';
|
|
10
8
|
export type AngularMemoryOutputFiles = Map<string, {
|
|
11
9
|
contents: Uint8Array;
|
|
12
10
|
servable: boolean;
|
|
13
11
|
}>;
|
|
14
12
|
export declare function pathnameWithoutBasePath(url: string, basePath: string): string;
|
|
15
13
|
export declare function lookupMimeTypeFromRequest(url: string): string | undefined;
|
|
16
|
-
export declare function appendServerConfiguredHeaders(server: ViteDevServer, res: ServerResponse<IncomingMessage>): void;
|
package/src/tools/vite/utils.js
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.pathnameWithoutBasePath = pathnameWithoutBasePath;
|
|
11
11
|
exports.lookupMimeTypeFromRequest = lookupMimeTypeFromRequest;
|
|
12
|
-
exports.appendServerConfiguredHeaders = appendServerConfiguredHeaders;
|
|
13
12
|
const mrmime_1 = require("mrmime");
|
|
14
13
|
const node_path_1 = require("node:path");
|
|
15
14
|
function pathnameWithoutBasePath(url, basePath) {
|
|
@@ -27,14 +26,3 @@ function lookupMimeTypeFromRequest(url) {
|
|
|
27
26
|
}
|
|
28
27
|
return extension && (0, mrmime_1.lookup)(extension);
|
|
29
28
|
}
|
|
30
|
-
function appendServerConfiguredHeaders(server, res) {
|
|
31
|
-
const headers = server.config.server.headers;
|
|
32
|
-
if (!headers) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
for (const [name, value] of Object.entries(headers)) {
|
|
36
|
-
if (value !== undefined) {
|
|
37
|
-
res.setHeader(name, value);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/typings.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// The `bundled_critters` causes issues with module mappings in Bazel,
|
|
10
|
+
// leading to unexpected behavior with esbuild. Specifically, the problem occurs
|
|
11
|
+
// when esbuild resolves to a different module or version than expected, due to
|
|
12
|
+
// how Bazel handles module mappings.
|
|
13
|
+
//
|
|
14
|
+
// This change aims to resolve esbuild types correctly and maintain consistency
|
|
15
|
+
// in the Bazel build process.
|
|
16
|
+
|
|
17
|
+
declare module 'esbuild' {
|
|
18
|
+
export * from 'esbuild-wasm';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Augment the Node.js module builtin types to support the v22.8+ compile cache functions
|
|
23
|
+
*/
|
|
24
|
+
declare module 'node:module' {
|
|
25
|
+
function getCompileCacheDir(): string | undefined;
|
|
26
|
+
}
|
|
@@ -15,3 +15,5 @@ export declare const shouldWatchRoot: boolean;
|
|
|
15
15
|
export declare const useTypeChecking: boolean;
|
|
16
16
|
export declare const useJSONBuildLogs: boolean;
|
|
17
17
|
export declare const shouldOptimizeChunks: boolean;
|
|
18
|
+
export declare const useComponentStyleHmr: boolean;
|
|
19
|
+
export declare const usePartialSsrBuild: boolean;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* found in the LICENSE file at https://angular.dev/license
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.shouldOptimizeChunks = exports.useJSONBuildLogs = exports.useTypeChecking = exports.shouldWatchRoot = exports.debugPerformance = exports.useParallelTs = exports.maxWorkers = exports.allowMinify = exports.shouldBeautify = exports.allowMangle = void 0;
|
|
10
|
+
exports.usePartialSsrBuild = exports.useComponentStyleHmr = exports.shouldOptimizeChunks = exports.useJSONBuildLogs = exports.useTypeChecking = exports.shouldWatchRoot = exports.debugPerformance = exports.useParallelTs = exports.maxWorkers = exports.allowMinify = exports.shouldBeautify = exports.allowMangle = void 0;
|
|
11
11
|
const node_os_1 = require("node:os");
|
|
12
12
|
function isDisabled(variable) {
|
|
13
13
|
return variable === '0' || variable.toLowerCase() === 'false';
|
|
@@ -82,3 +82,7 @@ const buildLogsJsonVariable = process.env['NG_BUILD_LOGS_JSON'];
|
|
|
82
82
|
exports.useJSONBuildLogs = isPresent(buildLogsJsonVariable) && isEnabled(buildLogsJsonVariable);
|
|
83
83
|
const optimizeChunksVariable = process.env['NG_BUILD_OPTIMIZE_CHUNKS'];
|
|
84
84
|
exports.shouldOptimizeChunks = isPresent(optimizeChunksVariable) && isEnabled(optimizeChunksVariable);
|
|
85
|
+
const hmrComponentStylesVariable = process.env['NG_HMR_CSTYLES'];
|
|
86
|
+
exports.useComponentStyleHmr = isPresent(hmrComponentStylesVariable) && isEnabled(hmrComponentStylesVariable);
|
|
87
|
+
const partialSsrBuildVariable = process.env['NG_BUILD_PARTIAL_SSR'];
|
|
88
|
+
exports.usePartialSsrBuild = isPresent(partialSsrBuildVariable) && isEnabled(partialSsrBuildVariable);
|
|
@@ -14,6 +14,7 @@ const add_event_dispatch_contract_1 = require("./add-event-dispatch-contract");
|
|
|
14
14
|
const augment_index_html_1 = require("./augment-index-html");
|
|
15
15
|
const inline_critical_css_1 = require("./inline-critical-css");
|
|
16
16
|
const inline_fonts_1 = require("./inline-fonts");
|
|
17
|
+
const ngcm_attribute_1 = require("./ngcm-attribute");
|
|
17
18
|
const nonce_1 = require("./nonce");
|
|
18
19
|
class IndexHtmlGenerator {
|
|
19
20
|
options;
|
|
@@ -35,6 +36,7 @@ class IndexHtmlGenerator {
|
|
|
35
36
|
this.csrPlugins.push(addNoncePlugin());
|
|
36
37
|
// SSR plugins
|
|
37
38
|
if (options.generateDedicatedSSRContent) {
|
|
39
|
+
this.csrPlugins.push(addNgcmAttributePlugin());
|
|
38
40
|
this.ssrPlugins.push(addEventDispatchContractPlugin(), addNoncePlugin());
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -134,3 +136,6 @@ function postTransformPlugin({ options }) {
|
|
|
134
136
|
function addEventDispatchContractPlugin() {
|
|
135
137
|
return (html) => (0, add_event_dispatch_contract_1.addEventDispatchContract)(html);
|
|
136
138
|
}
|
|
139
|
+
function addNgcmAttributePlugin() {
|
|
140
|
+
return (html) => (0, ngcm_attribute_1.addNgcmAttribute)(html);
|
|
141
|
+
}
|