Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: check for parser
  • Loading branch information
sapphi-red committed Jan 7, 2025
commit f177476232968889391e1037b6c4fb7030eb1ccc
11 changes: 7 additions & 4 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,11 @@ async function compileCSS(
)
}

if (lang !== 'sss' && !postcssPlugins.length) {
const postcssOptions = postcssConfig?.options ?? {}
const postcssParser =
lang === 'sss' ? loadSss(config.root) : postcssOptions.parser

if (!postcssPlugins.length && !postcssParser) {
return {
code,
map: preprocessorMap,
Expand All @@ -1446,12 +1450,11 @@ async function compileCSS(
try {
const source = removeDirectQuery(id)
const postcss = await importPostcss()
const postcssOptions = postcssConfig?.options ?? {}

// postcss is an unbundled dep and should be lazy imported
postcssResult = await postcss.default(postcssPlugins).process(code, {
...postcssOptions,
parser: lang === 'sss' ? loadSss(config.root) : postcssOptions.parser,
parser: postcssParser,
to: source,
from: source,
...(devSourcemap
Expand Down Expand Up @@ -2156,7 +2159,7 @@ function loadSassPackage(root: string): {
}

let cachedSss: any
function loadSss(root: string) {
function loadSss(root: string): PostCSS.Syntax {
if (cachedSss) return cachedSss

const sssPath = loadPreprocessorPath(PostCssDialectLang.sss, root)
Expand Down
Loading