@@ -139,14 +139,14 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
139139
140140 // Get final asset URL. If the file does not exist,
141141 // we fall back to the initial URL and let it resolve in runtime
142- let builtUrl : string | undefined
142+ let builtUrlExpr : string | undefined
143143 if ( file ) {
144144 try {
145145 if ( publicDir && isParentDirectory ( publicDir , file ) ) {
146146 const publicPath = '/' + path . posix . relative ( publicDir , file )
147- builtUrl = await fileToUrl ( this , publicPath )
147+ builtUrlExpr = await fileToUrl ( this , publicPath , 'js' )
148148 } else {
149- builtUrl = await fileToUrl ( this , file )
149+ builtUrlExpr = await fileToUrl ( this , file , 'js' )
150150 // during dev, builtUrl may point to a directory or a non-existing file
151151 if ( tryStatSync ( file ) ?. isFile ( ) ) {
152152 this . addWatchFile ( file )
@@ -156,19 +156,19 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
156156 // do nothing, we'll log a warning after this
157157 }
158158 }
159- if ( ! builtUrl ) {
159+ if ( ! builtUrlExpr ) {
160160 const rawExp = code . slice ( startIndex , endIndex )
161161 config . logger . warnOnce (
162162 `\n${ rawExp } doesn't exist at build time, it will remain unchanged to be resolved at runtime. ` +
163163 `If this is intended, you can use the /* @vite-ignore */ comment to suppress this warning.` ,
164164 )
165- builtUrl = url
165+ builtUrlExpr = JSON . stringify ( url )
166166 }
167167 s . update (
168168 startIndex ,
169169 endIndex ,
170170 // NOTE: add `'' +` to opt-out rolldown's transform: https://github.com/rolldown/rolldown/issues/2745
171- `new URL(${ JSON . stringify ( builtUrl ) } , '' + import.meta.url)` ,
171+ `new URL(${ builtUrlExpr } , '' + import.meta.url)` ,
172172 )
173173 }
174174 if ( s ) {
0 commit comments