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
Note the build will fail if the code contains features that cannot be safely transpiled by esbuild. See [esbuild docs](https://esbuild.github.io/content-types/#javascript) for more details.
482
482
483
+
### build.polyfillDynamicImport
484
+
485
+
-**Type:**`boolean`
486
+
-**Default:**`false`
487
+
488
+
Whether to automatically inject [dynamic import polyfill](https://github.com/GoogleChromeLabs/dynamic-import-polyfill).
489
+
490
+
If set to true, the polyfill is auto injected into the proxy module of each `index.html` entry. If the build is configured to use a non-html custom entry via `build.rollupOptions.input`, then it is necessary to manually import the polyfill in your custom entry:
491
+
492
+
```js
493
+
import'vite/dynamic-import-polyfill'
494
+
```
495
+
496
+
When using [`@vitejs/plugin-legacy`](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy), the plugin sets this option to `true` automatically.
497
+
498
+
Note: the polyfill does **not** apply to [Library Mode](/guide/build#library-mode). If you need to support browsers without native dynamic import, you should probably avoid using it in your library.
Copy file name to clipboardExpand all lines: docs/guide/backend-integration.md
+7
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,13 @@ Or you can follow these steps to configure it manually:
20
20
}
21
21
```
22
22
23
+
If you use [`@vitejs/plugin-legacy`](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) or manually enable the [`build.dynamicImportPolyfill` option](/config/#build-polyfilldynamicimport), remember to add the [dynamic import polyfill](/config/#build-polyfilldynamicimport) to your entry, since it will no longer be auto-injected:
24
+
25
+
```js
26
+
// add the beginning of your app entry
27
+
import'vite/dynamic-import-polyfill'
28
+
```
29
+
23
30
2. For development, inject the following in your server's HTML template (substitute `http://localhost:3000` with the local URL Vite is running at):
@@ -16,11 +31,114 @@ export function dynamicImportPolyfillPlugin(config: ResolvedConfig): Plugin {
16
31
},
17
32
load(id){
18
33
if(id===polyfillId){
19
-
config.logger.warn(
20
-
`\n'vite/dynamic-import-polyfill' is no longer needed, refer to https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#230-2021-05-10`
34
+
if(!enabled){
35
+
config.logger.warnOnce(
36
+
`\n'vite/dynamic-import-polyfill' is no longer needed if you target modern browsers`
37
+
)
38
+
}
39
+
if(skip){
40
+
return''
41
+
}
42
+
// return a placeholder here and defer the injection to renderChunk
43
+
// so that we can selectively skip the injection based on output format
0 commit comments