Skip to content

Commit

Permalink
fix!: put manifest files in .vite directory by default (#14230)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Sep 18, 2023
1 parent dc5896c commit 74fa024
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Build as a library. `entry` is required since the library cannot use HTML as ent
- **Default:** `false`
- **Related:** [Backend Integration](/guide/backend-integration)
When set to `true`, the build will also generate a `manifest.json` file that contains a mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. When the value is a string, it will be used as the manifest file name.
When set to `true`, the build will also generate a `.vite/manifest.json` file that contains a mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. When the value is a string, it will be used as the manifest file name.
## build.ssrManifest
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/backend-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you need a custom integration, you can follow the steps in this guide to conf
// vite.config.js
export default defineConfig({
build: {
// generate manifest.json in outDir
// generate .vite/manifest.json in outDir
manifest: true,
rollupOptions: {
// overwrite default .html entry
Expand Down Expand Up @@ -56,7 +56,7 @@ If you need a custom integration, you can follow the steps in this guide to conf
</script>
```

3. For production: after running `vite build`, a `manifest.json` file will be generated alongside other asset files. An example manifest file looks like this:
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:

```json
{
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ Refer to the [Vue](https://github.com/vitejs/vite-plugin-vue/tree/main/playgroun
## Generating Preload Directives
`vite build` supports the `--ssrManifest` flag which will generate `ssr-manifest.json` in build output directory:
`vite build` supports the `--ssrManifest` flag which will generate `.vite/ssr-manifest.json` in build output directory:
```diff
- "build:client": "vite build --outDir dist/client",
+ "build:client": "vite build --outDir dist/client --ssrManifest",
```
The above script will now generate `dist/client/ssr-manifest.json` for the client build (Yes, the SSR manifest is generated from the client build because we want to map module IDs to client files). The manifest contains mappings of module IDs to their associated chunks and asset files.
The above script will now generate `dist/client/.vite/ssr-manifest.json` for the client build (Yes, the SSR manifest is generated from the client build because we want to map module IDs to client files). The manifest contains mappings of module IDs to their associated chunks and asset files.
To leverage the manifest, frameworks need to provide a way to collect the module IDs of the components that were used during a server render call.
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export interface BuildOptions {
*/
copyPublicDir?: boolean
/**
* Whether to emit a manifest.json under assets dir to map hash-less filenames
* Whether to emit a .vite/manifest.json under assets dir to map hash-less filenames
* to their hashed versions. Useful when you want to generate your own HTML
* instead of using the one generated by Vite.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
fileName:
typeof config.build.manifest === 'string'
? config.build.manifest
: 'manifest.json',
: '.vite/manifest.json',
type: 'asset',
source: jsonStableStringify(manifest, { space: 2 }),
})
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrManifestPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin {
fileName:
typeof config.build.ssrManifest === 'string'
? config.build.ssrManifest
: 'ssr-manifest.json',
: '.vite/ssr-manifest.json',
type: 'asset',
source: jsonStableStringify(ssrManifest, { space: 2 }),
})
Expand Down
5 changes: 4 additions & 1 deletion playground/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ export function findAssetFile(

export function readManifest(base = ''): Manifest {
return JSON.parse(
fs.readFileSync(path.join(testDir, 'dist', base, 'manifest.json'), 'utf-8'),
fs.readFileSync(
path.join(testDir, 'dist', base, '.vite/manifest.json'),
'utf-8',
),
)
}

Expand Down

0 comments on commit 74fa024

Please sign in to comment.