Skip to content

Commit cbd40f9

Browse files
committed
chore: remove direct query only
1 parent acfa047 commit cbd40f9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
normalizePath,
4343
parseRequest,
4444
processSrcSet,
45+
removeDirectQuery,
4546
requireResolveFromRootWithFallback
4647
} from '../utils'
4748
import type { Logger } from '../logger'
@@ -753,7 +754,6 @@ async function compileCSS(
753754
preprocessorOptions,
754755
devSourcemap
755756
} = config.css || {}
756-
const fileName = cleanUrl(id)
757757
const isModule = modulesOptions !== false && cssModuleRE.test(id)
758758
// although at serve time it can work without processing, we do need to
759759
// crawl them in order to register watch dependencies.
@@ -801,7 +801,7 @@ async function compileCSS(
801801
}
802802
}
803803
// important: set this for relative import resolving
804-
opts.filename = fileName
804+
opts.filename = cleanUrl(id)
805805
opts.enableSourcemap = devSourcemap ?? false
806806

807807
const preprocessResult = await preProcessor(
@@ -915,13 +915,14 @@ async function compileCSS(
915915

916916
let postcssResult: PostCSS.Result
917917
try {
918+
const source = removeDirectQuery(id)
918919
// postcss is an unbundled dep and should be lazy imported
919920
postcssResult = await (await import('postcss'))
920921
.default(postcssPlugins)
921922
.process(code, {
922923
...postcssOptions,
923-
to: fileName,
924-
from: fileName,
924+
to: source,
925+
from: source,
925926
...(devSourcemap
926927
? {
927928
map: {
@@ -991,13 +992,13 @@ async function compileCSS(
991992
// version property of rawPostcssMap is declared as string
992993
// but actually it is a number
993994
rawPostcssMap as Omit<RawSourceMap, 'version'> as ExistingRawSourceMap,
994-
fileName
995+
cleanUrl(id)
995996
)
996997

997998
return {
998999
ast: postcssResult,
9991000
code: postcssResult.css,
1000-
map: combineSourcemapsIfExists(fileName, postcssMap, preprocessorMap),
1001+
map: combineSourcemapsIfExists(cleanUrl(id), postcssMap, preprocessorMap),
10011002
modules,
10021003
deps
10031004
}

packages/vite/src/node/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export function getPotentialTsSrcPaths(filePath: string): string[] {
303303
}
304304

305305
const importQueryRE = /(\?|&)import=?(?:&|$)/
306+
const directRequestRE = /(\?|&)direct(?:&|$)/
306307
const internalPrefixes = [
307308
FS_PREFIX,
308309
VALID_ID_PREFIX,
@@ -318,6 +319,9 @@ export const isInternalRequest = (url: string): boolean =>
318319
export function removeImportQuery(url: string): string {
319320
return url.replace(importQueryRE, '$1').replace(trailingSeparatorRE, '')
320321
}
322+
export function removeDirectQuery(url: string): string {
323+
return url.replace(directRequestRE, '$1').replace(trailingSeparatorRE, '')
324+
}
321325

322326
export function injectQuery(url: string, queryToInject: string): string {
323327
// encode percents for consistent behavior with pathToFileURL

0 commit comments

Comments
 (0)