Skip to content

Commit

Permalink
chore: remove direct query only
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 19, 2022
1 parent acfa047 commit cbd40f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
normalizePath,
parseRequest,
processSrcSet,
removeDirectQuery,
requireResolveFromRootWithFallback
} from '../utils'
import type { Logger } from '../logger'
Expand Down Expand Up @@ -753,7 +754,6 @@ async function compileCSS(
preprocessorOptions,
devSourcemap
} = config.css || {}
const fileName = cleanUrl(id)
const isModule = modulesOptions !== false && cssModuleRE.test(id)
// although at serve time it can work without processing, we do need to
// crawl them in order to register watch dependencies.
Expand Down Expand Up @@ -801,7 +801,7 @@ async function compileCSS(
}
}
// important: set this for relative import resolving
opts.filename = fileName
opts.filename = cleanUrl(id)
opts.enableSourcemap = devSourcemap ?? false

const preprocessResult = await preProcessor(
Expand Down Expand Up @@ -915,13 +915,14 @@ async function compileCSS(

let postcssResult: PostCSS.Result
try {
const source = removeDirectQuery(id)
// postcss is an unbundled dep and should be lazy imported
postcssResult = await (await import('postcss'))
.default(postcssPlugins)
.process(code, {
...postcssOptions,
to: fileName,
from: fileName,
to: source,
from: source,
...(devSourcemap
? {
map: {
Expand Down Expand Up @@ -991,13 +992,13 @@ async function compileCSS(
// version property of rawPostcssMap is declared as string
// but actually it is a number
rawPostcssMap as Omit<RawSourceMap, 'version'> as ExistingRawSourceMap,
fileName
cleanUrl(id)
)

return {
ast: postcssResult,
code: postcssResult.css,
map: combineSourcemapsIfExists(fileName, postcssMap, preprocessorMap),
map: combineSourcemapsIfExists(cleanUrl(id), postcssMap, preprocessorMap),
modules,
deps
}
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export function getPotentialTsSrcPaths(filePath: string): string[] {
}

const importQueryRE = /(\?|&)import=?(?:&|$)/
const directRequestRE = /(\?|&)direct(?:&|$)/
const internalPrefixes = [
FS_PREFIX,
VALID_ID_PREFIX,
Expand All @@ -318,6 +319,9 @@ export const isInternalRequest = (url: string): boolean =>
export function removeImportQuery(url: string): string {
return url.replace(importQueryRE, '$1').replace(trailingSeparatorRE, '')
}
export function removeDirectQuery(url: string): string {
return url.replace(directRequestRE, '$1').replace(trailingSeparatorRE, '')
}

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

0 comments on commit cbd40f9

Please sign in to comment.