@@ -26,7 +26,7 @@ import type { RawSourceMap } from '@ampproject/remapping'
26
26
import { getCodeWithSourcemap , injectSourcesContent } from '../server/sourcemap'
27
27
import type { ModuleNode } from '../server/moduleGraph'
28
28
import type { ResolveFn , ViteDevServer } from '../'
29
- import { toOutputFilePathInCss } from '../build'
29
+ import { resolveUserExternal , toOutputFilePathInCss } from '../build'
30
30
import {
31
31
CLIENT_PUBLIC_PATH ,
32
32
CSS_LANGS_RE ,
@@ -230,10 +230,21 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
230
230
return fileToUrl ( resolved , config , this )
231
231
}
232
232
if ( config . command === 'build' ) {
233
- // #9800 If we cannot resolve the css url, leave a warning.
234
- config . logger . warnOnce (
235
- `\n${ url } referenced in ${ id } didn't resolve at build time, it will remain unchanged to be resolved at runtime` ,
236
- )
233
+ const isExternal = config . build . rollupOptions . external
234
+ ? resolveUserExternal (
235
+ config . build . rollupOptions . external ,
236
+ url , // use URL as id since id could not be resolved
237
+ id ,
238
+ false ,
239
+ )
240
+ : false
241
+
242
+ if ( ! isExternal ) {
243
+ // #9800 If we cannot resolve the css url, leave a warning.
244
+ config . logger . warnOnce (
245
+ `\n${ url } referenced in ${ id } didn't resolve at build time, it will remain unchanged to be resolved at runtime` ,
246
+ )
247
+ }
237
248
}
238
249
return url
239
250
}
0 commit comments