File tree 1 file changed +11
-1
lines changed
packages/vite/src/node/plugins
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { dynamicImportToGlob } from '@rollup/plugin-dynamic-import-vars'
7
7
import type { KnownAsTypeMap } from 'types/importGlob'
8
8
import type { Plugin } from '../plugin'
9
9
import type { ResolvedConfig } from '../config'
10
+ import { CLIENT_ENTRY } from '../constants'
10
11
import {
11
12
createFilter ,
12
13
normalizePath ,
@@ -20,6 +21,11 @@ import { toAbsoluteGlob } from './importMetaGlob'
20
21
export const dynamicImportHelperId = '\0vite/dynamic-import-helper'
21
22
22
23
const relativePathRE = / ^ \. { 1 , 2 } \/ /
24
+ // fast path to check if source contains a dynamic import. we check for a
25
+ // trailing slash too as a dynamic import statement can have comments between
26
+ // the `import` and the `(`.
27
+ const hasDynamicImportRE = / \b i m p o r t \s * [ ( / ] /
28
+
23
29
interface DynamicImportRequest {
24
30
as ?: keyof KnownAsTypeMap
25
31
}
@@ -162,7 +168,11 @@ export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin {
162
168
} ,
163
169
164
170
async transform ( source , importer ) {
165
- if ( ! filter ( importer ) ) {
171
+ if (
172
+ ! filter ( importer ) ||
173
+ importer === CLIENT_ENTRY ||
174
+ ! hasDynamicImportRE . test ( source )
175
+ ) {
166
176
return
167
177
}
168
178
You can’t perform that action at this time.
0 commit comments