Skip to content

Commit 0e4553b

Browse files
committed
chore: merge main
2 parents 4dab15e + 3f7598c commit 0e4553b

File tree

24 files changed

+130
-47
lines changed

24 files changed

+130
-47
lines changed

docs/changes/hotupdate-hook.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ We're planning to deprecate the `handleHotUpdate` plugin hook in favor of [`hotU
99
Affected scope: `Vite Plugin Authors`
1010

1111
::: warning Future Deprecation
12-
`hotUpdate` was first introduced in `v6.0`. The deprecation of `handleHotUpdate` is planned for a future major. We don't yet recommend moving away from `handleHotUpdate` yet. If you want to experiment and give us feedback, you can use the `future.removePluginHookHandleHotUpdate` to `"warn"` in your vite config.
12+
`hotUpdate` was first introduced in `v6.0`. The deprecation of `handleHotUpdate` is planned for a future major. We don't recommend moving away from `handleHotUpdate` yet. If you want to experiment and give us feedback, you can use the `future.removePluginHookHandleHotUpdate` to `"warn"` in your vite config.
1313
:::
1414

1515
## Motivation
1616

17-
The [`handleHotUpdate` hook](/guide/api-plugin.md#handlehotupdate) allows to perform custom HMR update handling. A list of modules to be updated is passed in the `HmrContext`
17+
The [`handleHotUpdate` hook](/guide/api-plugin.md#handlehotupdate) allows to perform custom HMR update handling. A list of modules to be updated is passed in the `HmrContext`.
1818

1919
```ts
2020
interface HmrContext {

docs/guide/backend-integration.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ If you need a custom integration, you can follow the steps in this guide to conf
7575
"file": "assets/shared-ChJ_j-JJ.css",
7676
"src": "_shared-ChJ_j-JJ.css"
7777
},
78+
"logo.svg": {
79+
"file": "assets/logo-BuPIv-2h.svg",
80+
"src": "logo.svg"
81+
},
7882
"baz.js": {
7983
"file": "assets/baz-B2H3sXNv.js",
8084
"name": "baz",
@@ -100,11 +104,31 @@ If you need a custom integration, you can follow the steps in this guide to conf
100104
}
101105
```
102106

103-
- The manifest has a `Record<name, chunk>` structure
104-
- For entry or dynamic entry chunks, the key is the relative src path from project root.
105-
- For non entry chunks, the key is the base name of the generated file prefixed with `_`.
106-
- For the CSS file generated when [`build.cssCodeSplit`](/config/build-options.md#build-csscodesplit) is `false`, the key is `style.css`.
107-
- Chunks will contain information on its static and dynamic imports (both are keys that map to the corresponding chunk in the manifest), and also its corresponding CSS and asset files (if any).
107+
The manifest has a `Record<name, chunk>` structure where each chunk follows the `ManifestChunk` interface:
108+
109+
```ts
110+
interface ManifestChunk {
111+
src?: string
112+
file: string
113+
css?: string[]
114+
assets?: string[]
115+
isEntry?: boolean
116+
name?: string
117+
names?: string[]
118+
isDynamicEntry?: boolean
119+
imports?: string[]
120+
dynamicImports?: string[]
121+
}
122+
```
123+
124+
Each entry in the manifest represents one of the following:
125+
- **Entry chunks**: Generated from files specified in [`build.rollupOptions.input`](https://rollupjs.org/configuration-options/#input). These chunks have `isEntry: true` and their key is the relative src path from project root.
126+
- **Dynamic entry chunks**: Generated from dynamic imports. These chunks have `isDynamicEntry: true` and their key is the relative src path from project root.
127+
- **Non-entry chunks**: Their key is the base name of the generated file prefixed with `_`.
128+
- **Asset chunks**: Generated from imported assets like images, fonts. Their key is the relative src path from project root.
129+
- **CSS files**: When [`build.cssCodeSplit`](/config/build-options.md#build-csscodesplit) is `false`, a single CSS file is generated with the key `style.css`. When `build.cssCodeSplit` is not `false`, the key is generated similar to JS chunks (i.e. entry chunks will not have `_` prefix and non-entry chunks will have `_` prefix).
130+
131+
Chunks will contain information on their static and dynamic imports (both are keys that map to the corresponding chunk in the manifest), and also their corresponding CSS and asset files (if any).
108132

109133
4. You can use this file to render links or preload directives with hashed filenames.
110134

@@ -129,14 +153,13 @@ If you need a custom integration, you can follow the steps in this guide to conf
129153
```
130154

131155
Specifically, a backend generating HTML should include the following tags given a manifest
132-
file and an entry point:
133-
- A `<link rel="stylesheet">` tag for each file in the entry point chunk's `css` list
134-
- Recursively follow all chunks in the entry point's `imports` list and include a
135-
`<link rel="stylesheet">` tag for each CSS file of each imported chunk.
136-
- A tag for the `file` key of the entry point chunk (`<script type="module">` for JavaScript,
137-
or `<link rel="stylesheet">` for CSS)
138-
- Optionally, `<link rel="modulepreload">` tag for the `file` of each imported JavaScript
139-
chunk, again recursively following the imports starting from the entry point chunk.
156+
file and an entry point. Note that following this order is recommended for optimal performance:
157+
1. A `<link rel="stylesheet">` tag for each file in the entry point chunk's `css` list (if it exists)
158+
2. Recursively follow all chunks in the entry point's `imports` list and include a
159+
`<link rel="stylesheet">` tag for each CSS file of each imported chunk's `css` list (if it exists).
160+
3. A tag for the `file` key of the entry point chunk. This can be `<script type="module">` for JavaScript, `<link rel="stylesheet">` for CSS.
161+
4. Optionally, `<link rel="modulepreload">` tag for the `file` of each imported JavaScript
162+
chunk, again recursively following the imports starting from the entry point chunk.
140163

141164
Following the above example manifest, for the entry point `views/foo.js` the following tags should be included in production:
142165

packages/vite/src/node/__tests__/__snapshots__/utils.spec.ts.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ exports[`generateCodeFrames > start with position 3`] = `
139139
"
140140
`;
141141

142+
exports[`generateCodeFrames > supports more than 1000 lines 1`] = `
143+
"
144+
1198 | // 1197
145+
1199 | // 1198
146+
1200 | // 1199
147+
| ^
148+
1201 | // 1200
149+
1202 | // 1201
150+
"
151+
`;
152+
142153
exports[`generateCodeFrames > works with CRLF 1`] = `
143154
"
144155
1 | import foo from './foo'

packages/vite/src/node/__tests__/environment.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ describe('custom environment conditions', () => {
2020
middlewareMode: true,
2121
ws: false,
2222
},
23+
// disable scanner for client env to suppress scanner warnings
24+
optimizeDeps: { entries: [] },
2325
environments: {
2426
// default
2527
ssr: {

packages/vite/src/node/__tests__/plugins/hooks.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const createServerWithPlugin = async (plugin: Plugin) => {
4141
logLevel: 'error',
4242
server: {
4343
middlewareMode: true,
44+
ws: false,
4445
},
4546
})
4647
onTestFinished(() => server.close())

packages/vite/src/node/__tests__/resolve.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('import and resolveId', () => {
1313
logLevel: 'error',
1414
server: {
1515
middlewareMode: true,
16+
ws: false,
1617
},
1718
})
1819
onTestFinished(() => server.close())

packages/vite/src/node/__tests__/runnerImport.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import { loadConfigFromFile } from 'vite'
44
import { runnerImport } from '../ssr/runnerImport'
55
import { slash } from '../../shared/utils'
66

7-
const [nvMajor, nvMinor] = process.versions.node.split('.').map(Number)
8-
const isTypeStrippingSupported =
9-
(nvMajor === 23 && nvMinor >= 6) || nvMajor >= 24
7+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
8+
const isTypeStrippingSupported = !!process.features.typescript
109

1110
describe('importing files using inlined environment', () => {
1211
const fixture = (name: string) =>

packages/vite/src/node/__tests__/utils.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ foo()
288288
// 2
289289
// 3
290290
`.trim()
291+
const veryLongSource = Array.from({ length: 2000 }, (_, i) => `// ${i}`).join(
292+
'\n',
293+
)
291294

292295
const expectSnapshot = (value: string) => {
293296
try {
@@ -340,6 +343,10 @@ foo()
340343
test('invalid start > end', () => {
341344
expectSnapshot(generateCodeFrame(source, 2, 0))
342345
})
346+
347+
test('supports more than 1000 lines', () => {
348+
expectSnapshot(generateCodeFrame(veryLongSource, { line: 1200, column: 0 }))
349+
})
343350
})
344351

345352
describe('getHash', () => {

packages/vite/src/node/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
491491
return {
492492
pre: [
493493
completeSystemWrapPlugin(),
494-
prepareOutDirPlugin(),
494+
...(!config.isWorker ? [prepareOutDirPlugin()] : []),
495495
perEnvironmentPlugin(
496496
'vite:rollup-options-plugins',
497497
async (environment) =>

packages/vite/src/node/plugins/css.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
619619
},
620620

621621
async renderChunk(code, chunk, opts, meta) {
622-
let chunkCSS = ''
622+
let chunkCSS: string | undefined
623623
const renderedModules = new Proxy(
624624
{} as Record<string, RenderedModule | undefined>,
625625
{
@@ -660,7 +660,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
660660
isPureCssChunk = false
661661
}
662662

663-
chunkCSS += styles.get(id)
663+
chunkCSS = (chunkCSS || '') + styles.get(id)
664664
} else if (!isJsChunkEmpty) {
665665
// if the module does not have a style, then it's not a pure css chunk.
666666
// this is true because in the `transform` hook above, only modules
@@ -823,7 +823,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
823823
}
824824
}
825825

826-
if (chunkCSS) {
826+
if (chunkCSS !== undefined) {
827827
if (isPureCssChunk && (opts.format === 'es' || opts.format === 'cjs')) {
828828
// this is a shared CSS-only chunk that is empty.
829829
pureCssChunks.add(chunk)
@@ -855,7 +855,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
855855

856856
// wait for previous tasks as well
857857
chunkCSS = await codeSplitEmitQueue.run(async () => {
858-
return finalizeCss(chunkCSS, true, config)
858+
return finalizeCss(chunkCSS!, true, config)
859859
})
860860

861861
// emit corresponding css file
@@ -2037,7 +2037,10 @@ function skipUrlReplacer(unquotedUrl: string) {
20372037
isExternalUrl(unquotedUrl) ||
20382038
isDataUrl(unquotedUrl) ||
20392039
unquotedUrl[0] === '#' ||
2040-
functionCallRE.test(unquotedUrl)
2040+
functionCallRE.test(unquotedUrl) ||
2041+
// skip if it is already a placeholder
2042+
unquotedUrl.startsWith('__VITE_ASSET__') ||
2043+
unquotedUrl.startsWith('__VITE_PUBLIC_ASSET__')
20412044
)
20422045
}
20432046
async function doUrlReplace(

0 commit comments

Comments
 (0)