Skip to content

Commit

Permalink
fix(css): initialize lightningCSS targets when not using options (#14872
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ArnaudBarre authored Nov 5, 2023
1 parent 11b1796 commit 12f9230
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export type ResolvedConfig = Readonly<
alias: Alias[]
}
plugins: readonly Plugin[]
css: ResolvedCSSOptions | undefined
css: ResolvedCSSOptions
esbuild: ESBuildOptions | false
server: ResolvedServerOptions
build: ResolvedBuildOptions
Expand Down
9 changes: 4 additions & 5 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,19 @@ export type ResolvedCSSOptions = Omit<CSSOptions, 'lightningcss'> & {

export function resolveCSSOptions(
options: CSSOptions | undefined,
): ResolvedCSSOptions | undefined {
if (options?.lightningcss) {
): ResolvedCSSOptions {
if (options?.transformer === 'lightningcss') {
return {
...options,
lightningcss: {
...options.lightningcss,
targets:
options.lightningcss.targets ??
options.lightningcss?.targets ??
convertTargets(ESBUILD_MODULES_TARGET),
},
}
}
// TS doesn't narrow the type with the previous if :/
return options as Omit<CSSOptions, 'lightningcss'>
return { ...options, lightningcss: undefined }
}

const cssModuleRE = new RegExp(`\\.module${CSS_LANGS_RE.source}`)
Expand Down

0 comments on commit 12f9230

Please sign in to comment.