Skip to content

Commit 46d3077

Browse files
authored
docs: clarify manifest.json imports field is JS chunks only (#21136)
1 parent 203a551 commit 46d3077

File tree

3 files changed

+98
-5
lines changed

3 files changed

+98
-5
lines changed

docs/.vitepress/config.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,27 @@ export default defineConfig({
478478
markdown: {
479479
// languages used for twoslash and jsdocs in twoslash
480480
languages: ['ts', 'js', 'json'],
481-
codeTransformers: [transformerTwoslash()],
481+
codeTransformers: [
482+
transformerTwoslash(),
483+
// add `style:*` support
484+
{
485+
root(hast) {
486+
const meta = this.options.meta?.__raw
487+
?.split(' ')
488+
.find((m) => m.startsWith('style:'))
489+
if (meta) {
490+
const style = meta.slice('style:'.length)
491+
const rootPre = hast.children.find(
492+
(n): n is typeof n & { type: 'element'; tagName: 'pre' } =>
493+
n.type === 'element' && n.tagName === 'pre',
494+
)
495+
if (rootPre) {
496+
rootPre.properties.style += '; ' + style
497+
}
498+
}
499+
},
500+
},
501+
],
482502
config(md) {
483503
md.use(groupIconMdPlugin, {
484504
titleBar: {

docs/guide/backend-integration.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ If you need a custom integration, you can follow the steps in this guide to conf
6464

6565
3. For production, after running `vite build`, a `.vite/manifest.json` file will be generated alongside other asset files. An example manifest file looks like this:
6666

67-
```json [.vite/manifest.json]
67+
```json [.vite/manifest.json] style:max-height:400px
6868
{
6969
"_shared-B7PI925R.js": {
7070
"file": "assets/shared-B7PI925R.js",
@@ -106,17 +106,53 @@ If you need a custom integration, you can follow the steps in this guide to conf
106106

107107
The manifest has a `Record<name, chunk>` structure where each chunk follows the `ManifestChunk` interface:
108108

109-
```ts
109+
```ts style:max-height:400px
110110
interface ManifestChunk {
111+
/**
112+
* The input file name of this chunk / asset if known
113+
*/
111114
src?: string
115+
/**
116+
* The output file name of this chunk / asset
117+
*/
112118
file: string
119+
/**
120+
* The list of CSS files imported by this chunk
121+
*
122+
* This field is only present in JS chunks.
123+
*/
113124
css?: string[]
125+
/**
126+
* The list of asset files imported by this chunk, excluding CSS files
127+
*
128+
* This field is only present in JS chunks.
129+
*/
114130
assets?: string[]
131+
/**
132+
* Whether this chunk or asset is an entry point
133+
*/
115134
isEntry?: boolean
135+
/**
136+
* The name of this chunk / asset if known
137+
*/
116138
name?: string
117-
names?: string[]
139+
/**
140+
* Whether this chunk is a dynamic entry point
141+
*
142+
* This field is only present in JS chunks.
143+
*/
118144
isDynamicEntry?: boolean
145+
/**
146+
* The list of statically imported chunks by this chunk
147+
*
148+
* The values are the keys of the manifest. This field is only present in JS chunks.
149+
*/
119150
imports?: string[]
151+
/**
152+
* The list of dynamically imported chunks by this chunk
153+
*
154+
* The values are the keys of the manifest. This field is only present in JS chunks.
155+
*/
120156
dynamicImports?: string[]
121157
}
122158
```
@@ -128,7 +164,7 @@ If you need a custom integration, you can follow the steps in this guide to conf
128164
- **Asset chunks**: Generated from imported assets like images, fonts. Their key is the relative src path from project root.
129165
- **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).
130166

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).
167+
JS chunks (chunks other than assets or CSS) 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).
132168

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

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,52 @@ const endsWithJSRE = /\.[cm]?js$/
1515
export type Manifest = Record<string, ManifestChunk>
1616

1717
export interface ManifestChunk {
18+
/**
19+
* The input file name of this chunk / asset if known
20+
*/
1821
src?: string
22+
/**
23+
* The output file name of this chunk / asset
24+
*/
1925
file: string
26+
/**
27+
* The list of CSS files imported by this chunk
28+
*
29+
* This field is only present in JS chunks.
30+
*/
2031
css?: string[]
32+
/**
33+
* The list of asset files imported by this chunk, excluding CSS files
34+
*
35+
* This field is only present in JS chunks.
36+
*/
2137
assets?: string[]
38+
/**
39+
* Whether this chunk or asset is an entry point
40+
*/
2241
isEntry?: boolean
42+
/**
43+
* The name of this chunk / asset if known
44+
*/
2345
name?: string
2446
// names field is deprecated (removed from types, but still emitted for backward compatibility)
47+
/**
48+
* Whether this chunk is a dynamic entry point
49+
*
50+
* This field is only present in JS chunks.
51+
*/
2552
isDynamicEntry?: boolean
53+
/**
54+
* The list of statically imported chunks by this chunk
55+
*
56+
* The values are the keys of the manifest. This field is only present in JS chunks.
57+
*/
2658
imports?: string[]
59+
/**
60+
* The list of dynamically imported chunks by this chunk
61+
*
62+
* The values are the keys of the manifest. This field is only present in JS chunks.
63+
*/
2764
dynamicImports?: string[]
2865
}
2966

0 commit comments

Comments
 (0)