Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): do not warn when URL in CSS is externalized #12873

Merged
merged 1 commit into from Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vite/src/node/build.ts
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
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