From 12f92305891052a7d479e54d708b5fc705596da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Sun, 5 Nov 2023 08:14:46 +0100 Subject: [PATCH] fix(css): initialize lightningCSS targets when not using options (#14872) --- packages/vite/src/node/config.ts | 2 +- packages/vite/src/node/plugins/css.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index a78b026c6ecf44..1ebfbbb02a5a6e 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -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 diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 74d766930ee59e..842daf68710a18 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -141,20 +141,19 @@ export type ResolvedCSSOptions = Omit & { 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 + return { ...options, lightningcss: undefined } } const cssModuleRE = new RegExp(`\\.module${CSS_LANGS_RE.source}`)