Skip to content

Commit 18041aa

Browse files
committed
build: update to vite version 6
This commit updates vite to version 6
1 parent 6714d90 commit 18041aa

File tree

7 files changed

+139
-61
lines changed

7 files changed

+139
-61
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
"unenv": "^1.10.0",
208208
"verdaccio": "6.0.2",
209209
"verdaccio-auth-memory": "^10.0.0",
210-
"vite": "5.4.11",
210+
"vite": "6.0.0",
211211
"watchpack": "2.4.2",
212212
"webpack": "5.96.1",
213213
"webpack-dev-middleware": "7.4.2",

packages/angular/build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"rollup": "4.27.4",
4242
"sass": "1.81.0",
4343
"semver": "7.6.3",
44-
"vite": "5.4.11",
44+
"vite": "6.0.0",
4545
"watchpack": "2.4.2"
4646
},
4747
"optionalDependencies": {

packages/angular/build/src/builders/dev-server/vite-server.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ export async function* serveWithVite(
273273
}
274274

275275
// To avoid disconnecting the array objects from the option, these arrays need to be mutated instead of replaced.
276-
let requiresServerRestart = false;
277276
if (result.detail?.['externalMetadata']) {
278277
const { implicitBrowser, implicitServer, explicit } = result.detail[
279278
'externalMetadata'
@@ -283,15 +282,6 @@ export async function* serveWithVite(
283282
);
284283
const implicitBrowserFiltered = implicitBrowser.filter((m) => !isAbsoluteUrl(m));
285284

286-
if (browserOptions.ssr && serverOptions.prebundle !== false) {
287-
const previousImplicitServer = new Set(externalMetadata.implicitServer);
288-
// Restart the server to force SSR dep re-optimization when a dependency has been added.
289-
// This is a workaround for: https://github.com/vitejs/vite/issues/14896
290-
requiresServerRestart = implicitServerFiltered.some(
291-
(dep) => !previousImplicitServer.has(dep),
292-
);
293-
}
294-
295285
// Empty Arrays to avoid growing unlimited with every re-build.
296286
externalMetadata.explicitBrowser.length = 0;
297287
externalMetadata.explicitServer.length = 0;
@@ -317,20 +307,14 @@ export async function* serveWithVite(
317307
...new Set([...server.config.server.fs.allow, ...assetFiles.values()]),
318308
];
319309

320-
if (requiresServerRestart) {
321-
// Restart the server to force SSR dep re-optimization when a dependency has been added.
322-
// This is a workaround for: https://github.com/vitejs/vite/issues/14896
323-
await server.restart();
324-
} else {
325-
await handleUpdate(
326-
normalizePath,
327-
generatedFiles,
328-
server,
329-
serverOptions,
330-
context.logger,
331-
componentStyles,
332-
);
333-
}
310+
await handleUpdate(
311+
normalizePath,
312+
generatedFiles,
313+
server,
314+
serverOptions,
315+
context.logger,
316+
componentStyles,
317+
);
334318
} else {
335319
const projectName = context.target?.project;
336320
if (!projectName) {
@@ -475,6 +459,11 @@ async function handleUpdate(
475459
return;
476460
}
477461

462+
if (destroyAngularServerAppCalled) {
463+
// Trigger module evaluation before reload to initiate dependency optimization.
464+
await server.ssrLoadModule('/main.server.mjs');
465+
}
466+
478467
if (serverOptions.hmr) {
479468
if (updatedFiles.every((f) => f.endsWith('.css'))) {
480469
let requiresReload = false;
@@ -705,11 +694,6 @@ export async function setupServer(
705694
// the Vite client-side code for browser reloading. These would be available by default but when
706695
// the `allow` option is explicitly configured, they must be included manually.
707696
allow: [cacheDir, join(serverOptions.workspaceRoot, 'node_modules'), ...assets.values()],
708-
709-
// Temporary disable cached FS checks.
710-
// This is because we configure `config.base` to a virtual directory which causes `getRealPath` to fail.
711-
// See: https://github.com/vitejs/vite/blob/b2873ac3936de25ca8784327cb9ef16bd4881805/packages/vite/src/node/fsUtils.ts#L45-L67
712-
cachedChecks: false,
713697
},
714698
// This is needed when `externalDependencies` is used to prevent Vite load errors.
715699
// NOTE: If Vite adds direct support for externals, this can be removed.

packages/angular/build/src/tools/vite/plugins/ssr-transform-plugin.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import remapping, { SourceMapInput } from '@ampproject/remapping';
10+
import type { SourceDescription } from 'rollup';
1011
import type { Plugin } from 'vite';
1112
import { loadEsmModule } from '../../../utils/load-esm';
1213

@@ -15,28 +16,19 @@ export async function createAngularSsrTransformPlugin(workspaceRoot: string): Pr
1516

1617
return {
1718
name: 'vite:angular-ssr-transform',
18-
enforce: 'pre',
19-
async configureServer(server) {
20-
const originalssrTransform = server.ssrTransform;
19+
enforce: 'post',
20+
transform(code, _id, { ssr, inMap }: { ssr?: boolean; inMap?: SourceMapInput } = {}) {
21+
if (!ssr || !inMap) {
22+
return null;
23+
}
2124

22-
server.ssrTransform = async (code, map, url, originalCode) => {
23-
const result = await originalssrTransform(code, null, url, originalCode);
24-
if (!result || !result.map || !map) {
25-
return result;
26-
}
25+
const remappedMap = remapping([inMap], () => null);
26+
// Set the sourcemap root to the workspace root. This is needed since we set a virtual path as root.
27+
remappedMap.sourceRoot = normalizePath(workspaceRoot) + '/';
2728

28-
const remappedMap = remapping(
29-
[result.map as SourceMapInput, map as SourceMapInput],
30-
() => null,
31-
);
32-
33-
// Set the sourcemap root to the workspace root. This is needed since we set a virtual path as root.
34-
remappedMap.sourceRoot = normalizePath(workspaceRoot) + '/';
35-
36-
return {
37-
...result,
38-
map: remappedMap as (typeof result)['map'],
39-
};
29+
return {
30+
code,
31+
map: remappedMap as SourceDescription['map'],
4032
};
4133
},
4234
};

tests/legacy-cli/e2e/tests/vite/reuse-dep-optimization-cache.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ export default async function () {
1717
await execAndWaitForOutputToMatch(
1818
'ng',
1919
['serve', '--port', `${port}`],
20-
/Dependencies bundled/,
20+
/bundle generation complete/,
2121
// Use CI:0 to force caching
2222
{ DEBUG: 'vite:deps', CI: '0' },
2323
);
2424

25-
// Make request so that vite writes the cache.
26-
const response = await fetch(`http://localhost:${port}/main.js`);
27-
assert(response.ok, `Expected 'response.ok' to be 'true'.`);
28-
2925
// Wait for vite to write to FS and stablize.
30-
await waitForAnyProcessOutputToMatch(/dependencies optimized/, 5000);
26+
await Promise.all([
27+
waitForAnyProcessOutputToMatch(/dependencies optimized/, 5000),
28+
fetch(`http://localhost:${port}/main.js`).then((r) =>
29+
assert(r.ok, `Expected 'response.ok' to be 'true'.`),
30+
),
31+
]);
3132

3233
// Terminate the dev-server
3334
await killAllProcesses();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import assert from 'node:assert';
2+
import { ng, waitForAnyProcessOutputToMatch } from '../../utils/process';
3+
import { installWorkspacePackages, uninstallPackage } from '../../utils/packages';
4+
import { ngServe, useSha } from '../../utils/project';
5+
import { getGlobalVariable } from '../../utils/env';
6+
import { readFile, writeFile } from '../../utils/fs';
7+
8+
export default async function () {
9+
assert(
10+
getGlobalVariable('argv')['esbuild'],
11+
'This test should not be called in the Webpack suite.',
12+
);
13+
14+
// Enable caching to test real development workflow.
15+
await ng('cache', 'clean');
16+
await ng('cache', 'on');
17+
18+
// Forcibly remove in case another test doesn't clean itself up.
19+
await uninstallPackage('@angular/ssr');
20+
await ng('add', '@angular/ssr', '--server-routing', '--skip-confirmation', '--skip-install');
21+
await useSha();
22+
await installWorkspacePackages();
23+
24+
const port = await ngServe();
25+
await validateResponse('/', /Hello,/);
26+
27+
await Promise.all([
28+
waitForAnyProcessOutputToMatch(
29+
/new dependencies optimized: @angular\/platform-browser\/animations\/async/,
30+
6000,
31+
),
32+
writeFile(
33+
'src/app/app.config.ts',
34+
`
35+
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
36+
${(await readFile('src/app/app.config.ts')).replace('provideRouter(routes),', 'provideAnimationsAsync(), provideRouter(routes),')}
37+
`,
38+
),
39+
]);
40+
41+
// Verify the app still works.
42+
await validateResponse('/', /Hello,/);
43+
44+
async function validateResponse(pathname: string, match: RegExp): Promise<void> {
45+
const response = await fetch(new URL(pathname, `http://localhost:${port}`));
46+
const text = await response.text();
47+
assert.match(text, match);
48+
}
49+
}

yarn.lock

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ __metadata:
395395
rollup: "npm:4.27.4"
396396
sass: "npm:1.81.0"
397397
semver: "npm:7.6.3"
398-
vite: "npm:5.4.11"
398+
vite: "npm:6.0.0"
399399
watchpack: "npm:2.4.2"
400400
peerDependencies:
401401
"@angular/compiler": ^19.0.0
@@ -782,7 +782,7 @@ __metadata:
782782
unenv: "npm:^1.10.0"
783783
verdaccio: "npm:6.0.2"
784784
verdaccio-auth-memory: "npm:^10.0.0"
785-
vite: "npm:5.4.11"
785+
vite: "npm:6.0.0"
786786
watchpack: "npm:2.4.2"
787787
webpack: "npm:5.96.1"
788788
webpack-dev-middleware: "npm:7.4.2"
@@ -15366,7 +15366,7 @@ __metadata:
1536615366
languageName: node
1536715367
linkType: hard
1536815368

15369-
"postcss@npm:8.4.49, postcss@npm:^8.2.14, postcss@npm:^8.4.33, postcss@npm:^8.4.43, postcss@npm:^8.4.47":
15369+
"postcss@npm:8.4.49, postcss@npm:^8.2.14, postcss@npm:^8.4.33, postcss@npm:^8.4.43, postcss@npm:^8.4.47, postcss@npm:^8.4.49":
1537015370
version: 8.4.49
1537115371
resolution: "postcss@npm:8.4.49"
1537215372
dependencies:
@@ -16358,7 +16358,7 @@ __metadata:
1635816358
languageName: node
1635916359
linkType: hard
1636016360

16361-
"rollup@npm:4.27.4, rollup@npm:^4.20.0, rollup@npm:^4.24.0, rollup@npm:^4.4.0":
16361+
"rollup@npm:4.27.4, rollup@npm:^4.20.0, rollup@npm:^4.23.0, rollup@npm:^4.24.0, rollup@npm:^4.4.0":
1636216362
version: 4.27.4
1636316363
resolution: "rollup@npm:4.27.4"
1636416364
dependencies:
@@ -18761,6 +18761,58 @@ __metadata:
1876118761
languageName: node
1876218762
linkType: hard
1876318763

18764+
"vite@npm:6.0.0":
18765+
version: 6.0.0
18766+
resolution: "vite@npm:6.0.0"
18767+
dependencies:
18768+
esbuild: "npm:^0.24.0"
18769+
fsevents: "npm:~2.3.3"
18770+
postcss: "npm:^8.4.49"
18771+
rollup: "npm:^4.23.0"
18772+
peerDependencies:
18773+
"@types/node": ^18.0.0 || ^20.0.0 || >=22.0.0
18774+
jiti: ">=1.21.0"
18775+
less: "*"
18776+
lightningcss: ^1.21.0
18777+
sass: "*"
18778+
sass-embedded: "*"
18779+
stylus: "*"
18780+
sugarss: "*"
18781+
terser: ^5.16.0
18782+
tsx: ^4.8.1
18783+
yaml: ^2.4.2
18784+
dependenciesMeta:
18785+
fsevents:
18786+
optional: true
18787+
peerDependenciesMeta:
18788+
"@types/node":
18789+
optional: true
18790+
jiti:
18791+
optional: true
18792+
less:
18793+
optional: true
18794+
lightningcss:
18795+
optional: true
18796+
sass:
18797+
optional: true
18798+
sass-embedded:
18799+
optional: true
18800+
stylus:
18801+
optional: true
18802+
sugarss:
18803+
optional: true
18804+
terser:
18805+
optional: true
18806+
tsx:
18807+
optional: true
18808+
yaml:
18809+
optional: true
18810+
bin:
18811+
vite: bin/vite.js
18812+
checksum: 10c0/2516144161c108452691ec1379aefd8f3201da8f225e628cb1cdb7b35b92d856d990cd31f1c36c0f36517346efe181ea3c096a04bc846c5b0d1416b7b7111af8
18813+
languageName: node
18814+
linkType: hard
18815+
1876418816
"void-elements@npm:^2.0.0":
1876518817
version: 2.0.1
1876618818
resolution: "void-elements@npm:2.0.1"

0 commit comments

Comments
 (0)