Skip to content

Commit bd1e019

Browse files
Copilotsapphi-red
andauthored
docs: improve manifest.json documentation clarity and completeness (vitejs#20524)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: sapphi-red <[email protected]>
1 parent 64a52e7 commit bd1e019

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

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

0 commit comments

Comments
 (0)