Skip to content

Commit

Permalink
fix(build): do not warn when URL in CSS is externalized (#12873)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Apr 15, 2023
1 parent 32bef57 commit 1510996
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,12 @@ async function cjsSsrResolveExternal(
}
}

function resolveUserExternal(
export function resolveUserExternal(
user: ExternalOption,
id: string,
parentId: string | undefined,
isResolved: boolean,
) {
): boolean | null | void {
if (typeof user === 'function') {
return user(id, parentId, isResolved)
} else if (Array.isArray(user)) {
Expand Down
21 changes: 16 additions & 5 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { RawSourceMap } from '@ampproject/remapping'
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
import type { ModuleNode } from '../server/moduleGraph'
import type { ResolveFn, ViteDevServer } from '../'
import { toOutputFilePathInCss } from '../build'
import { resolveUserExternal, toOutputFilePathInCss } from '../build'
import {
CLIENT_PUBLIC_PATH,
CSS_LANGS_RE,
Expand Down Expand Up @@ -230,10 +230,21 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
return fileToUrl(resolved, config, this)
}
if (config.command === 'build') {
// #9800 If we cannot resolve the css url, leave a warning.
config.logger.warnOnce(
`\n${url} referenced in ${id} didn't resolve at build time, it will remain unchanged to be resolved at runtime`,
)
const isExternal = config.build.rollupOptions.external
? resolveUserExternal(
config.build.rollupOptions.external,
url, // use URL as id since id could not be resolved
id,
false,
)
: false

if (!isExternal) {
// #9800 If we cannot resolve the css url, leave a warning.
config.logger.warnOnce(
`\n${url} referenced in ${id} didn't resolve at build time, it will remain unchanged to be resolved at runtime`,
)
}
}
return url
}
Expand Down

0 comments on commit 1510996

Please sign in to comment.