diff --git a/docs/guide/build.md b/docs/guide/build.md index 962c6fc419b587..a9c79c3d44c1f5 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -64,6 +64,18 @@ This strategy is also provided as a `splitVendorChunk({ cache: SplitVendorChunkC You should use `build.rollupOptions.output.manualChunks` function form when using this plugin. If the object form is used, the plugin won't have any effect. ::: +## Load Error Handling + +Vite emits `vite:preloadError` event when it fails to load dynamic imports. `event.payload` contains the original import error. If you call `event.preventDefault()`, the error will not be thrown. + +```js +window.addEventListener('vite:preloadError', (event) => { + window.reload() // for example, refresh the page +}) +``` + +When a new deployment occurs, the hosting service may delete the assets from previous deployments. As a result, a user who visited your site before the new deployment might encounter an import error. This error happens because the assets running on that user's device are outdated and it tries to import the corresponding old chunk, which is deleted. This event is useful for addressing this situation. + ## Rebuild on files changes You can enable rollup watcher with `vite build --watch`. Or, you can directly adjust the underlying [`WatcherOptions`](https://rollupjs.org/configuration-options/#watch) via `build.watch`: