@@ -11,6 +11,7 @@ import { fileToUrl } from './asset'
1111import { preloadHelperId } from './importAnalysisBuild'
1212import type { InternalResolveOptions } from './resolve'
1313import { tryFsResolve } from './resolve'
14+ import { hasViteIgnoreRE } from './importAnalysis'
1415
1516/**
1617 * Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL
@@ -54,6 +55,8 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
5455 let match : RegExpExecArray | null
5556 while ( ( match = assetImportMetaUrlRE . exec ( cleanString ) ) ) {
5657 const [ [ startIndex , endIndex ] , [ urlStart , urlEnd ] ] = match . indices !
58+ if ( hasViteIgnoreRE . test ( code . slice ( startIndex , urlStart ) ) ) continue
59+
5760 const rawUrl = code . slice ( urlStart , urlEnd )
5861
5962 if ( ! s ) s = new MagicString ( code )
@@ -134,7 +137,8 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
134137 if ( ! builtUrl ) {
135138 const rawExp = code . slice ( startIndex , endIndex )
136139 config . logger . warnOnce (
137- `\n${ rawExp } doesn't exist at build time, it will remain unchanged to be resolved at runtime` ,
140+ `\n${ rawExp } doesn't exist at build time, it will remain unchanged to be resolved at runtime. ` +
141+ `If this is intended, you can use the /* @vite-ignore */ comment to suppress this warning.` ,
138142 )
139143 builtUrl = url
140144 }
0 commit comments