Skip to content

Commit 1510996

Browse files
authoredApr 15, 2023
fix(build): do not warn when URL in CSS is externalized (#12873)
1 parent 32bef57 commit 1510996

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed
 

‎packages/vite/src/node/build.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -947,12 +947,12 @@ async function cjsSsrResolveExternal(
947947
}
948948
}
949949

950-
function resolveUserExternal(
950+
export function resolveUserExternal(
951951
user: ExternalOption,
952952
id: string,
953953
parentId: string | undefined,
954954
isResolved: boolean,
955-
) {
955+
): boolean | null | void {
956956
if (typeof user === 'function') {
957957
return user(id, parentId, isResolved)
958958
} else if (Array.isArray(user)) {

‎packages/vite/src/node/plugins/css.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type { RawSourceMap } from '@ampproject/remapping'
2626
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
2727
import type { ModuleNode } from '../server/moduleGraph'
2828
import type { ResolveFn, ViteDevServer } from '../'
29-
import { toOutputFilePathInCss } from '../build'
29+
import { resolveUserExternal, toOutputFilePathInCss } from '../build'
3030
import {
3131
CLIENT_PUBLIC_PATH,
3232
CSS_LANGS_RE,
@@ -230,10 +230,21 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
230230
return fileToUrl(resolved, config, this)
231231
}
232232
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+
}
237248
}
238249
return url
239250
}

0 commit comments

Comments
 (0)
Please sign in to comment.