You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/build.md
+58
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,8 @@ JS-imported asset URLs, CSS `url()` references, and asset references in your `.h
27
27
28
28
The exception is when you need to dynamically concatenate URLs on the fly. In this case, you can use the globally injected `import.meta.env.BASE_URL` variable which will be the public base path. Note this variable is statically replaced during build so it must appear exactly as-is (i.e. `import.meta.env['BASE_URL']` won't work).
29
29
30
+
For advanced base path control, check out [Advanced Base Options](#advanced-base-options).
31
+
30
32
## Customizing the Build
31
33
32
34
The build can be customized via various [build config options](/config/build-options.md). Specifically, you can directly adjust the underlying [Rollup options](https://rollupjs.org/guide/en/#big-list-of-options) via `build.rollupOptions`:
@@ -181,3 +183,59 @@ Recommended `package.json` for your lib:
181
183
}
182
184
}
183
185
```
186
+
187
+
## Advanced Base Options
188
+
189
+
::: warning
190
+
This feature is experimental, the API may change in a future minor without following semver. Please fix the minor version of Vite when using it.
191
+
:::
192
+
193
+
For advanced use cases, the deployed assets and public files may be in different paths, for example to use different cache strategies.
194
+
A user may choose to deploy in three different paths:
195
+
196
+
- The generated entry HTML files (which may be processed during SSR)
197
+
- The generated hashed assets (JS, CSS, and other file types like images)
198
+
- The copied [public files](assets.md#the-public-directory)
199
+
200
+
A single static [base](#public-base-path) isn't enough in these scenarios. Vite provides experimental support for advanced base options during build, using `experimental.buildAdvancedBaseOptions`.
When `runtime` is defined, it will be used for hashed assets and public files paths inside JS assets. Inside CSS and HTML generated files, paths will use `url` if defined or fallback to `config.base`.
219
+
220
+
If `relative` is true and `url` is defined, relative paths will be prefered for assets inside the same group (for example a hashed image referenced from a JS file). And `url` will be used for the paths in HTML entries and for paths between different groups (a public file referenced from a CSS file).
221
+
222
+
If the hashed assets and public files aren't deployed together, options for each group can be defined independently:
0 commit comments