@angular/build 20.2.0 → 21.0.0-next.0
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/.browserslistrc +5 -5
- package/package.json +15 -15
- package/src/builders/dev-server/builder.js +2 -2
- package/src/builders/dev-server/vite/hmr.d.ts +25 -0
- package/src/builders/dev-server/vite/hmr.js +113 -0
- package/src/builders/dev-server/vite/index.d.ts +21 -0
- package/src/builders/dev-server/{vite-server.js → vite/index.js} +19 -359
- package/src/builders/dev-server/vite/server.d.ts +15 -0
- package/src/builders/dev-server/vite/server.js +229 -0
- package/src/builders/dev-server/vite/utils.d.ts +36 -0
- package/src/builders/dev-server/vite/utils.js +76 -0
- package/src/builders/unit-test/builder.d.ts +1 -1
- package/src/builders/unit-test/builder.js +187 -289
- package/src/builders/unit-test/options.d.ts +1 -0
- package/src/builders/unit-test/options.js +2 -1
- package/src/builders/unit-test/runners/api.d.ts +47 -0
- package/src/builders/unit-test/runners/api.js +9 -0
- package/src/builders/unit-test/runners/karma/executor.d.ts +17 -0
- package/src/builders/unit-test/runners/karma/executor.js +93 -0
- package/src/builders/unit-test/runners/karma/index.d.ts +13 -0
- package/src/builders/unit-test/runners/karma/index.js +26 -0
- package/src/builders/unit-test/runners/vitest/browser-provider.d.ts +11 -0
- package/src/builders/unit-test/runners/vitest/browser-provider.js +69 -0
- package/src/builders/unit-test/runners/vitest/build-options.d.ts +11 -0
- package/src/builders/unit-test/runners/vitest/build-options.js +87 -0
- package/src/builders/unit-test/runners/vitest/executor.d.ts +22 -0
- package/src/builders/unit-test/runners/vitest/executor.js +160 -0
- package/src/builders/unit-test/runners/vitest/index.d.ts +13 -0
- package/src/builders/unit-test/runners/vitest/index.js +30 -0
- package/src/builders/unit-test/schema.d.ts +4 -0
- package/src/builders/unit-test/schema.json +4 -0
- package/src/builders/unit-test/test-discovery.d.ts +8 -0
- package/src/builders/unit-test/test-discovery.js +14 -0
- package/src/private.d.ts +1 -1
- package/src/private.js +2 -2
- package/src/utils/environment-options.d.ts +43 -0
- package/src/utils/environment-options.js +84 -30
- package/src/utils/normalize-cache.js +1 -1
- package/src/utils/version.js +1 -1
- package/src/builders/dev-server/vite-server.d.ts +0 -42
- package/src/builders/unit-test/karma-bridge.d.ts +0 -10
- package/src/builders/unit-test/karma-bridge.js +0 -82
|
@@ -44,19 +44,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.serveWithVite = serveWithVite;
|
|
47
|
-
exports.setupServer = setupServer;
|
|
48
47
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
49
|
-
const promises_1 = require("node:fs/promises");
|
|
50
48
|
const node_module_1 = require("node:module");
|
|
51
49
|
const node_path_1 = require("node:path");
|
|
52
|
-
const plugins_1 = require("
|
|
53
|
-
const utils_1 = require("
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
50
|
+
const plugins_1 = require("../../../tools/vite/plugins");
|
|
51
|
+
const utils_1 = require("../../../utils");
|
|
52
|
+
const environment_options_1 = require("../../../utils/environment-options");
|
|
53
|
+
const load_esm_1 = require("../../../utils/load-esm");
|
|
54
|
+
const results_1 = require("../../application/results");
|
|
55
|
+
const schema_1 = require("../../application/schema");
|
|
56
|
+
const internal_1 = require("../internal");
|
|
57
|
+
const hmr_1 = require("./hmr");
|
|
58
|
+
const server_1 = require("./server");
|
|
59
|
+
const utils_2 = require("./utils");
|
|
60
60
|
/**
|
|
61
61
|
* Build options that are also present on the dev server but are only passed
|
|
62
62
|
* to the build.
|
|
@@ -110,7 +110,7 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
110
110
|
// When localization is enabled with a single locale, force a flat path to maintain behavior with the existing Webpack-based dev server.
|
|
111
111
|
browserOptions.forceI18nFlatOutput = true;
|
|
112
112
|
}
|
|
113
|
-
const { vendor: thirdPartySourcemaps, scripts: scriptsSourcemaps } = (0,
|
|
113
|
+
const { vendor: thirdPartySourcemaps, scripts: scriptsSourcemaps } = (0, utils_1.normalizeSourceMaps)(browserOptions.sourceMap ?? false);
|
|
114
114
|
if (scriptsSourcemaps && browserOptions.server) {
|
|
115
115
|
// https://nodejs.org/api/process.html#processsetsourcemapsenabledval
|
|
116
116
|
process.setSourceMapsEnabled(true);
|
|
@@ -203,7 +203,7 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
203
203
|
componentStyles.clear();
|
|
204
204
|
generatedFiles.clear();
|
|
205
205
|
for (const [outputPath, file] of Object.entries(result.files)) {
|
|
206
|
-
updateResultRecord(outputPath, file, normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles,
|
|
206
|
+
(0, utils_2.updateResultRecord)(outputPath, file, normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles,
|
|
207
207
|
// The initial build will not yet have a server setup
|
|
208
208
|
!server);
|
|
209
209
|
}
|
|
@@ -220,10 +220,10 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
220
220
|
assetFiles.delete(filePath);
|
|
221
221
|
}
|
|
222
222
|
for (const modified of result.modified) {
|
|
223
|
-
updateResultRecord(modified, result.files[modified], normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles);
|
|
223
|
+
(0, utils_2.updateResultRecord)(modified, result.files[modified], normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles);
|
|
224
224
|
}
|
|
225
225
|
for (const added of result.added) {
|
|
226
|
-
updateResultRecord(added, result.files[added], normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles);
|
|
226
|
+
(0, utils_2.updateResultRecord)(added, result.files[added], normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles);
|
|
227
227
|
}
|
|
228
228
|
break;
|
|
229
229
|
case results_1.ResultKind.ComponentUpdate:
|
|
@@ -247,8 +247,8 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
247
247
|
// To avoid disconnecting the array objects from the option, these arrays need to be mutated instead of replaced.
|
|
248
248
|
if (result.detail?.['externalMetadata']) {
|
|
249
249
|
const { implicitBrowser, implicitServer, explicit } = result.detail['externalMetadata'];
|
|
250
|
-
const implicitServerFiltered = implicitServer.filter((m) => !(0, node_module_1.isBuiltin)(m) && !isAbsoluteUrl(m));
|
|
251
|
-
const implicitBrowserFiltered = implicitBrowser.filter((m) => !isAbsoluteUrl(m));
|
|
250
|
+
const implicitServerFiltered = implicitServer.filter((m) => !(0, node_module_1.isBuiltin)(m) && !(0, utils_2.isAbsoluteUrl)(m));
|
|
251
|
+
const implicitBrowserFiltered = implicitBrowser.filter((m) => !(0, utils_2.isAbsoluteUrl)(m));
|
|
252
252
|
// Empty Arrays to avoid growing unlimited with every re-build.
|
|
253
253
|
externalMetadata.explicitBrowser.length = 0;
|
|
254
254
|
externalMetadata.explicitServer.length = 0;
|
|
@@ -274,9 +274,9 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
274
274
|
...[...assetFiles.values()].map(({ source }) => source),
|
|
275
275
|
]),
|
|
276
276
|
];
|
|
277
|
-
const updatedFiles = await invalidateUpdatedFiles(normalizePath, generatedFiles, assetFiles, server);
|
|
277
|
+
const updatedFiles = await (0, hmr_1.invalidateUpdatedFiles)(normalizePath, generatedFiles, assetFiles, server);
|
|
278
278
|
if (needClientUpdate) {
|
|
279
|
-
handleUpdate(server, serverOptions, context.logger, componentStyles, updatedFiles);
|
|
279
|
+
(0, hmr_1.handleUpdate)(server, serverOptions, context.logger, componentStyles, updatedFiles);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
else {
|
|
@@ -315,7 +315,7 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
317
|
// Setup server and start listening
|
|
318
|
-
const serverConfiguration = await setupServer(serverOptions, generatedFiles, assetFiles, browserOptions.preserveSymlinks, externalMetadata, ssrMode, prebundleTransformer, target, (0, internal_1.isZonelessApp)(polyfills), componentStyles, templateUpdates, browserOptions.loader, {
|
|
318
|
+
const serverConfiguration = await (0, server_1.setupServer)(serverOptions, generatedFiles, assetFiles, browserOptions.preserveSymlinks, externalMetadata, ssrMode, prebundleTransformer, target, (0, internal_1.isZonelessApp)(polyfills), componentStyles, templateUpdates, browserOptions.loader, {
|
|
319
319
|
...browserOptions.define,
|
|
320
320
|
'ngHmrMode': browserOptions.templateUpdates ? 'true' : 'false',
|
|
321
321
|
}, extensions?.middleware, transformers?.indexHtml, thirdPartySourcemaps);
|
|
@@ -393,343 +393,3 @@ async function* serveWithVite(serverOptions, builderName, builderAction, context
|
|
|
393
393
|
}
|
|
394
394
|
await new Promise((resolve) => (deferred = resolve));
|
|
395
395
|
}
|
|
396
|
-
/**
|
|
397
|
-
* Invalidates any updated asset or generated files and resets their `updated` state.
|
|
398
|
-
* This function also clears the server application cache when necessary.
|
|
399
|
-
*
|
|
400
|
-
* @returns A list of files that were updated and invalidated.
|
|
401
|
-
*/
|
|
402
|
-
async function invalidateUpdatedFiles(normalizePath, generatedFiles, assetFiles, server) {
|
|
403
|
-
const updatedFiles = [];
|
|
404
|
-
// Invalidate any updated asset
|
|
405
|
-
for (const [file, record] of assetFiles) {
|
|
406
|
-
if (!record.updated) {
|
|
407
|
-
continue;
|
|
408
|
-
}
|
|
409
|
-
record.updated = false;
|
|
410
|
-
updatedFiles.push(file);
|
|
411
|
-
}
|
|
412
|
-
// Invalidate any updated files
|
|
413
|
-
let serverApplicationChanged = false;
|
|
414
|
-
for (const [file, record] of generatedFiles) {
|
|
415
|
-
if (!record.updated) {
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
record.updated = false;
|
|
419
|
-
updatedFiles.push(file);
|
|
420
|
-
serverApplicationChanged ||= record.type === internal_1.BuildOutputFileType.ServerApplication;
|
|
421
|
-
const updatedModules = server.moduleGraph.getModulesByFile(normalizePath((0, node_path_1.join)(server.config.root, file)));
|
|
422
|
-
updatedModules?.forEach((m) => server.moduleGraph.invalidateModule(m));
|
|
423
|
-
}
|
|
424
|
-
if (serverApplicationChanged) {
|
|
425
|
-
// Clear the server app cache and
|
|
426
|
-
// trigger module evaluation before reload to initiate dependency optimization.
|
|
427
|
-
const { ɵdestroyAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs'));
|
|
428
|
-
ɵdestroyAngularServerApp();
|
|
429
|
-
}
|
|
430
|
-
return updatedFiles;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Handles updates for the client by sending HMR or full page reload commands
|
|
434
|
-
* based on the updated files. It also ensures proper tracking of component styles and determines if
|
|
435
|
-
* a full reload is needed.
|
|
436
|
-
*/
|
|
437
|
-
function handleUpdate(server, serverOptions, logger, componentStyles, updatedFiles) {
|
|
438
|
-
if (!updatedFiles.length) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
if (serverOptions.hmr) {
|
|
442
|
-
if (updatedFiles.every((f) => f.endsWith('.css'))) {
|
|
443
|
-
let requiresReload = false;
|
|
444
|
-
const timestamp = Date.now();
|
|
445
|
-
const updates = updatedFiles.flatMap((filePath) => {
|
|
446
|
-
// For component styles, an HMR update must be sent for each one with the corresponding
|
|
447
|
-
// component identifier search parameter (`ngcomp`). The Vite client code will not keep
|
|
448
|
-
// the existing search parameters when it performs an update and each one must be
|
|
449
|
-
// specified explicitly. Typically, there is only one each though as specific style files
|
|
450
|
-
// are not typically reused across components.
|
|
451
|
-
const record = componentStyles.get(filePath);
|
|
452
|
-
if (record) {
|
|
453
|
-
if (record.reload) {
|
|
454
|
-
// Shadow DOM components currently require a full reload.
|
|
455
|
-
// Vite's CSS hot replacement does not support shadow root searching.
|
|
456
|
-
requiresReload = true;
|
|
457
|
-
return [];
|
|
458
|
-
}
|
|
459
|
-
return Array.from(record.used ?? []).map((id) => {
|
|
460
|
-
return {
|
|
461
|
-
type: 'css-update',
|
|
462
|
-
timestamp,
|
|
463
|
-
path: `${filePath}?ngcomp` + (typeof id === 'string' ? `=${id}` : ''),
|
|
464
|
-
acceptedPath: filePath,
|
|
465
|
-
};
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
return {
|
|
469
|
-
type: 'css-update',
|
|
470
|
-
timestamp,
|
|
471
|
-
path: filePath,
|
|
472
|
-
acceptedPath: filePath,
|
|
473
|
-
};
|
|
474
|
-
});
|
|
475
|
-
if (!requiresReload) {
|
|
476
|
-
server.ws.send({
|
|
477
|
-
type: 'update',
|
|
478
|
-
updates,
|
|
479
|
-
});
|
|
480
|
-
logger.info('Stylesheet update sent to client(s).');
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
// Send reload command to clients
|
|
486
|
-
if (serverOptions.liveReload) {
|
|
487
|
-
// Clear used component tracking on full reload
|
|
488
|
-
componentStyles.forEach((record) => record.used?.clear());
|
|
489
|
-
server.ws.send({
|
|
490
|
-
type: 'full-reload',
|
|
491
|
-
path: '*',
|
|
492
|
-
});
|
|
493
|
-
logger.info('Page reload sent to client(s).');
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
function updateResultRecord(outputPath, file, normalizePath, htmlIndexPath, generatedFiles, assetFiles, componentStyles, initial = false) {
|
|
497
|
-
if (file.origin === 'disk') {
|
|
498
|
-
assetFiles.set('/' + normalizePath(outputPath), {
|
|
499
|
-
source: normalizePath(file.inputPath),
|
|
500
|
-
updated: !initial,
|
|
501
|
-
});
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
let filePath;
|
|
505
|
-
if (outputPath === htmlIndexPath) {
|
|
506
|
-
// Convert custom index output path to standard index path for dev-server usage.
|
|
507
|
-
// This mimics the Webpack dev-server behavior.
|
|
508
|
-
filePath = '/index.html';
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
filePath = '/' + normalizePath(outputPath);
|
|
512
|
-
}
|
|
513
|
-
const servable = file.type === internal_1.BuildOutputFileType.Browser || file.type === internal_1.BuildOutputFileType.Media;
|
|
514
|
-
// Skip analysis of sourcemaps
|
|
515
|
-
if (filePath.endsWith('.map')) {
|
|
516
|
-
generatedFiles.set(filePath, {
|
|
517
|
-
contents: file.contents,
|
|
518
|
-
servable,
|
|
519
|
-
size: file.contents.byteLength,
|
|
520
|
-
hash: file.hash,
|
|
521
|
-
type: file.type,
|
|
522
|
-
updated: false,
|
|
523
|
-
});
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
// New or updated file
|
|
527
|
-
generatedFiles.set(filePath, {
|
|
528
|
-
contents: file.contents,
|
|
529
|
-
size: file.contents.byteLength,
|
|
530
|
-
hash: file.hash,
|
|
531
|
-
// Consider the files updated except on the initial build result
|
|
532
|
-
updated: !initial,
|
|
533
|
-
type: file.type,
|
|
534
|
-
servable,
|
|
535
|
-
});
|
|
536
|
-
// Record any external component styles
|
|
537
|
-
if (filePath.endsWith('.css') && /^\/[a-f0-9]{64}\.css$/.test(filePath)) {
|
|
538
|
-
const componentStyle = componentStyles.get(filePath);
|
|
539
|
-
if (componentStyle) {
|
|
540
|
-
componentStyle.rawContent = file.contents;
|
|
541
|
-
}
|
|
542
|
-
else {
|
|
543
|
-
componentStyles.set(filePath, {
|
|
544
|
-
rawContent: file.contents,
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
// eslint-disable-next-line max-lines-per-function
|
|
550
|
-
async function setupServer(serverOptions, outputFiles, assets, preserveSymlinks, externalMetadata, ssrMode, prebundleTransformer, target, zoneless, componentStyles, templateUpdates, prebundleLoaderExtensions, define, extensionMiddleware, indexHtmlTransformer, thirdPartySourcemaps = false) {
|
|
551
|
-
const proxy = await (0, utils_2.loadProxyConfiguration)(serverOptions.workspaceRoot, serverOptions.proxyConfig);
|
|
552
|
-
// dynamically import Vite for ESM compatibility
|
|
553
|
-
const { normalizePath } = await (0, load_esm_1.loadEsmModule)('vite');
|
|
554
|
-
// Path will not exist on disk and only used to provide separate path for Vite requests
|
|
555
|
-
const virtualProjectRoot = normalizePath((0, node_path_1.join)(serverOptions.workspaceRoot, `.angular/vite-root`, serverOptions.buildTarget.project));
|
|
556
|
-
// Files used for SSR warmup.
|
|
557
|
-
let ssrFiles;
|
|
558
|
-
switch (ssrMode) {
|
|
559
|
-
case plugins_1.ServerSsrMode.InternalSsrMiddleware:
|
|
560
|
-
ssrFiles = ['./main.server.mjs'];
|
|
561
|
-
break;
|
|
562
|
-
case plugins_1.ServerSsrMode.ExternalSsrMiddleware:
|
|
563
|
-
ssrFiles = ['./main.server.mjs', './server.mjs'];
|
|
564
|
-
break;
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Required when using `externalDependencies` to prevent Vite load errors.
|
|
568
|
-
*
|
|
569
|
-
* @note Can be removed if Vite introduces native support for externals.
|
|
570
|
-
* @note Vite misresolves browser modules in SSR when accessing URLs with multiple segments
|
|
571
|
-
* (e.g., 'foo/bar'), as they are not correctly re-based from the base href.
|
|
572
|
-
*/
|
|
573
|
-
const preTransformRequests = externalMetadata.explicitBrowser.length === 0 && ssrMode === plugins_1.ServerSsrMode.NoSsr;
|
|
574
|
-
const cacheDir = (0, node_path_1.join)(serverOptions.cacheOptions.path, serverOptions.buildTarget.project, 'vite');
|
|
575
|
-
const configuration = {
|
|
576
|
-
configFile: false,
|
|
577
|
-
envFile: false,
|
|
578
|
-
cacheDir,
|
|
579
|
-
root: virtualProjectRoot,
|
|
580
|
-
publicDir: false,
|
|
581
|
-
esbuild: false,
|
|
582
|
-
mode: 'development',
|
|
583
|
-
// We use custom as we do not rely on Vite's htmlFallbackMiddleware and indexHtmlMiddleware.
|
|
584
|
-
appType: 'custom',
|
|
585
|
-
css: {
|
|
586
|
-
devSourcemap: true,
|
|
587
|
-
},
|
|
588
|
-
// Ensure custom 'file' loader build option entries are handled by Vite in application code that
|
|
589
|
-
// reference third-party libraries. Relative usage is handled directly by the build and not Vite.
|
|
590
|
-
// Only 'file' loader entries are currently supported directly by Vite.
|
|
591
|
-
assetsInclude: prebundleLoaderExtensions &&
|
|
592
|
-
Object.entries(prebundleLoaderExtensions)
|
|
593
|
-
.filter(([, value]) => value === 'file')
|
|
594
|
-
// Create a file extension glob for each key
|
|
595
|
-
.map(([key]) => '*' + key),
|
|
596
|
-
// Vite will normalize the `base` option by adding a leading slash.
|
|
597
|
-
base: serverOptions.servePath,
|
|
598
|
-
resolve: {
|
|
599
|
-
mainFields: ['es2020', 'browser', 'module', 'main'],
|
|
600
|
-
preserveSymlinks,
|
|
601
|
-
},
|
|
602
|
-
dev: {
|
|
603
|
-
preTransformRequests,
|
|
604
|
-
},
|
|
605
|
-
server: {
|
|
606
|
-
preTransformRequests,
|
|
607
|
-
warmup: {
|
|
608
|
-
ssrFiles,
|
|
609
|
-
},
|
|
610
|
-
port: serverOptions.port,
|
|
611
|
-
strictPort: true,
|
|
612
|
-
host: serverOptions.host,
|
|
613
|
-
open: serverOptions.open,
|
|
614
|
-
allowedHosts: serverOptions.allowedHosts,
|
|
615
|
-
headers: serverOptions.headers,
|
|
616
|
-
// Disable the websocket if live reload is disabled (false/undefined are the only valid values)
|
|
617
|
-
ws: serverOptions.liveReload === false && serverOptions.hmr === false ? false : undefined,
|
|
618
|
-
// When server-side rendering (SSR) is enabled togather with SSL and Express is being used,
|
|
619
|
-
// we must configure Vite to use HTTP/1.1.
|
|
620
|
-
// This is necessary because Express does not support HTTP/2.
|
|
621
|
-
// We achieve this by defining an empty proxy.
|
|
622
|
-
// See: https://github.com/vitejs/vite/blob/c4b532cc900bf988073583511f57bd581755d5e3/packages/vite/src/node/http.ts#L106
|
|
623
|
-
proxy: serverOptions.ssl && ssrMode === plugins_1.ServerSsrMode.ExternalSsrMiddleware
|
|
624
|
-
? (proxy ?? {})
|
|
625
|
-
: proxy,
|
|
626
|
-
cors: {
|
|
627
|
-
// This will add the header `Access-Control-Allow-Origin: http://example.com`,
|
|
628
|
-
// where `http://example.com` is the requesting origin.
|
|
629
|
-
origin: true,
|
|
630
|
-
// Allow preflight requests to be proxied.
|
|
631
|
-
preflightContinue: true,
|
|
632
|
-
},
|
|
633
|
-
// File watching is handled by the build directly. `null` disables file watching for Vite.
|
|
634
|
-
watch: null,
|
|
635
|
-
fs: {
|
|
636
|
-
// Ensure cache directory, node modules, and all assets are accessible by the client.
|
|
637
|
-
// The first two are required for Vite to function in prebundling mode (the default) and to load
|
|
638
|
-
// the Vite client-side code for browser reloading. These would be available by default but when
|
|
639
|
-
// the `allow` option is explicitly configured, they must be included manually.
|
|
640
|
-
allow: [
|
|
641
|
-
cacheDir,
|
|
642
|
-
(0, node_path_1.join)(serverOptions.workspaceRoot, 'node_modules'),
|
|
643
|
-
...[...assets.values()].map(({ source }) => source),
|
|
644
|
-
],
|
|
645
|
-
},
|
|
646
|
-
},
|
|
647
|
-
ssr: {
|
|
648
|
-
// Note: `true` and `/.*/` have different sematics. When true, the `external` option is ignored.
|
|
649
|
-
noExternal: /.*/,
|
|
650
|
-
// Exclude any Node.js built in module and provided dependencies (currently build defined externals)
|
|
651
|
-
external: externalMetadata.explicitServer,
|
|
652
|
-
optimizeDeps: (0, utils_1.getDepOptimizationConfig)({
|
|
653
|
-
// Only enable with caching since it causes prebundle dependencies to be cached
|
|
654
|
-
disabled: serverOptions.prebundle === false,
|
|
655
|
-
// Exclude any explicitly defined dependencies (currently build defined externals and node.js built-ins)
|
|
656
|
-
exclude: externalMetadata.explicitServer,
|
|
657
|
-
// Include all implict dependencies from the external packages internal option
|
|
658
|
-
include: externalMetadata.implicitServer,
|
|
659
|
-
ssr: true,
|
|
660
|
-
prebundleTransformer,
|
|
661
|
-
zoneless,
|
|
662
|
-
target,
|
|
663
|
-
loader: prebundleLoaderExtensions,
|
|
664
|
-
thirdPartySourcemaps,
|
|
665
|
-
define,
|
|
666
|
-
}),
|
|
667
|
-
},
|
|
668
|
-
plugins: [
|
|
669
|
-
(0, plugins_1.createAngularLocaleDataPlugin)(),
|
|
670
|
-
(0, plugins_1.createAngularSetupMiddlewaresPlugin)({
|
|
671
|
-
outputFiles,
|
|
672
|
-
assets,
|
|
673
|
-
indexHtmlTransformer,
|
|
674
|
-
extensionMiddleware,
|
|
675
|
-
componentStyles,
|
|
676
|
-
templateUpdates,
|
|
677
|
-
ssrMode,
|
|
678
|
-
resetComponentUpdates: () => templateUpdates.clear(),
|
|
679
|
-
projectRoot: serverOptions.projectRoot,
|
|
680
|
-
}),
|
|
681
|
-
(0, plugins_1.createRemoveIdPrefixPlugin)(externalMetadata.explicitBrowser),
|
|
682
|
-
await (0, plugins_1.createAngularSsrTransformPlugin)(serverOptions.workspaceRoot),
|
|
683
|
-
await (0, plugins_1.createAngularMemoryPlugin)({
|
|
684
|
-
virtualProjectRoot,
|
|
685
|
-
outputFiles,
|
|
686
|
-
templateUpdates,
|
|
687
|
-
external: externalMetadata.explicitBrowser,
|
|
688
|
-
disableViteTransport: !serverOptions.liveReload,
|
|
689
|
-
}),
|
|
690
|
-
],
|
|
691
|
-
// Browser only optimizeDeps. (This does not run for SSR dependencies).
|
|
692
|
-
optimizeDeps: (0, utils_1.getDepOptimizationConfig)({
|
|
693
|
-
// Only enable with caching since it causes prebundle dependencies to be cached
|
|
694
|
-
disabled: serverOptions.prebundle === false,
|
|
695
|
-
// Exclude any explicitly defined dependencies (currently build defined externals)
|
|
696
|
-
exclude: externalMetadata.explicitBrowser,
|
|
697
|
-
// Include all implict dependencies from the external packages internal option
|
|
698
|
-
include: externalMetadata.implicitBrowser,
|
|
699
|
-
ssr: false,
|
|
700
|
-
prebundleTransformer,
|
|
701
|
-
target,
|
|
702
|
-
zoneless,
|
|
703
|
-
loader: prebundleLoaderExtensions,
|
|
704
|
-
thirdPartySourcemaps,
|
|
705
|
-
define,
|
|
706
|
-
}),
|
|
707
|
-
};
|
|
708
|
-
if (serverOptions.ssl) {
|
|
709
|
-
if (serverOptions.sslCert && serverOptions.sslKey) {
|
|
710
|
-
configuration.server ??= {};
|
|
711
|
-
// server configuration is defined above
|
|
712
|
-
configuration.server.https = {
|
|
713
|
-
cert: await (0, promises_1.readFile)(serverOptions.sslCert),
|
|
714
|
-
key: await (0, promises_1.readFile)(serverOptions.sslKey),
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
const { default: basicSslPlugin } = await Promise.resolve().then(() => __importStar(require('@vitejs/plugin-basic-ssl')));
|
|
719
|
-
configuration.plugins ??= [];
|
|
720
|
-
configuration.plugins.push(basicSslPlugin());
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
return configuration;
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Checks if the given value is an absolute URL.
|
|
727
|
-
*
|
|
728
|
-
* This function helps in avoiding Vite's prebundling from processing absolute URLs (http://, https://, //) as files.
|
|
729
|
-
*
|
|
730
|
-
* @param value - The URL or path to check.
|
|
731
|
-
* @returns `true` if the value is not an absolute URL; otherwise, `false`.
|
|
732
|
-
*/
|
|
733
|
-
function isAbsoluteUrl(value) {
|
|
734
|
-
return /^(?:https?:)?\/\//.test(value);
|
|
735
|
-
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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, InlineConfig } from 'vite';
|
|
9
|
+
import type { ComponentStyleRecord } from '../../../tools/vite/middlewares';
|
|
10
|
+
import { ServerSsrMode } from '../../../tools/vite/plugins';
|
|
11
|
+
import { EsbuildLoaderOption } from '../../../tools/vite/utils';
|
|
12
|
+
import { type ApplicationBuilderInternalOptions, JavaScriptTransformer } from '../internal';
|
|
13
|
+
import type { NormalizedDevServerOptions } from '../options';
|
|
14
|
+
import { DevServerExternalResultMetadata, OutputAssetRecord, OutputFileRecord } from './utils';
|
|
15
|
+
export declare function setupServer(serverOptions: NormalizedDevServerOptions, outputFiles: Map<string, OutputFileRecord>, assets: Map<string, OutputAssetRecord>, preserveSymlinks: boolean | undefined, externalMetadata: DevServerExternalResultMetadata, ssrMode: ServerSsrMode, prebundleTransformer: JavaScriptTransformer, target: string[], zoneless: boolean, componentStyles: Map<string, ComponentStyleRecord>, templateUpdates: Map<string, string>, prebundleLoaderExtensions: EsbuildLoaderOption | undefined, define: ApplicationBuilderInternalOptions['define'], extensionMiddleware?: Connect.NextHandleFunction[], indexHtmlTransformer?: (content: string) => Promise<string>, thirdPartySourcemaps?: boolean): Promise<InlineConfig>;
|