diff --git a/docs/config/index.md b/docs/config/index.md index 9ed1d9d6de9136..a3380888874147 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -320,7 +320,7 @@ export default ({ command, mode }) => { 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: ```js - import 'vite/dynamic-import-polyfill' + import '/vite/dynamic-import-polyfill' ``` 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. diff --git a/docs/guide/backend-integration.md b/docs/guide/backend-integration.md index fa9675b69e1747..2a63335ea4a030 100644 --- a/docs/guide/backend-integration.md +++ b/docs/guide/backend-integration.md @@ -21,7 +21,7 @@ If you want to serve the HTML using a traditional backend (e.g. Rails, Laravel) ```js // add the beginning of your app entry - import 'vite/dynamic-import-polyfill' + import '/vite/dynamic-import-polyfill' ``` 2. For development, inject the following in your server's HTML template (substitute `http://localhost:3000` with the local URL Vite is running at): diff --git a/packages/vite/src/node/plugins/dynamicImportPolyfill.ts b/packages/vite/src/node/plugins/dynamicImportPolyfill.ts index 3d84a3b0c55420..0e4b8a6543129a 100644 --- a/packages/vite/src/node/plugins/dynamicImportPolyfill.ts +++ b/packages/vite/src/node/plugins/dynamicImportPolyfill.ts @@ -2,7 +2,7 @@ import { ResolvedConfig } from '..' import { Plugin } from '../plugin' import { isModernFlag } from './importAnaysisBuild' -export const polyfillId = 'vite/dynamic-import-polyfill' +export const polyfillId = '/vite/dynamic-import-polyfill' export function dynamicImportPolyfillPlugin(config: ResolvedConfig): Plugin { const skip = config.command === 'serve' || config.build.ssr @@ -17,6 +17,11 @@ export function dynamicImportPolyfillPlugin(config: ResolvedConfig): Plugin { if (id === polyfillId) { return id } + if (id === 'vite/dynamic-import-polyfill') { + this.error( + `The 'vite/dynamic-import-polyfill' is deprecated, Please use '/vite/dynamic-import-polyfill'.` + ) + } }, load(id) { if (id === polyfillId) {