@@ -79,6 +79,8 @@ export const hasViteIgnoreRE = /\/\*\s*@vite-ignore\s*\*\//
7979const cleanUpRawUrlRE = / \/ \* [ \s \S ] * ?\* \/ | ( [ ^ \\ : ] | ^ ) \/ \/ .* $ / gm
8080const urlIsStringRE = / ^ (?: ' .* ' | " .* " | ` .* ` ) $ /
8181
82+ const templateLiteralRE = / ^ \s * ` ( .* ) ` \s * $ /
83+
8284interface UrlPosition {
8385 url : string
8486 start : number
@@ -423,12 +425,13 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
423425 ss : expStart ,
424426 se : expEnd ,
425427 d : dynamicIndex ,
426- // #2083 User may use escape path,
427- // so use imports[index].n to get the unescaped string
428- n : specifier ,
429428 a : assertIndex ,
430429 } = importSpecifier
431430
431+ // #2083 User may use escape path,
432+ // so use imports[index].n to get the unescaped string
433+ let specifier = importSpecifier . n
434+
432435 const rawUrl = source . slice ( start , end )
433436
434437 // check import.meta usage
@@ -466,6 +469,14 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
466469 hasEnv = true
467470 }
468471 return
472+ } else if ( templateLiteralRE . test ( rawUrl ) ) {
473+ // If the import has backticks but isn't transformed as a glob import
474+ // (as there's nothing to glob), check if it's simply a plain string.
475+ // If so, we can replace the specifier as a plain string to prevent
476+ // an incorrect "cannot be analyzed" warning.
477+ if ( ! ( rawUrl . includes ( '${' ) && rawUrl . includes ( '}' ) ) ) {
478+ specifier = rawUrl . replace ( templateLiteralRE , '$1' )
479+ }
469480 }
470481
471482 const isDynamicImport = dynamicIndex > - 1
0 commit comments