From eb88400c8a384f964acb021755f45644dd4670bd Mon Sep 17 00:00:00 2001 From: Adam Skoufis Date: Sat, 23 Mar 2024 16:55:03 +1100 Subject: [PATCH] Fix propagation of the user's vite config in vite-based frameworks that don't use a vite.config.js file --- .changeset/clever-elephants-rest.md | 5 +++++ packages/vite-plugin/src/index.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/clever-elephants-rest.md diff --git a/.changeset/clever-elephants-rest.md b/.changeset/clever-elephants-rest.md new file mode 100644 index 00000000..14612bf2 --- /dev/null +++ b/.changeset/clever-elephants-rest.md @@ -0,0 +1,5 @@ +--- +'@vanilla-extract/vite-plugin': patch +--- + +Fixes a bug that prevented propagation of the user's vite config to the `vite-node` compiler in vite-based frameworks that don't use a `vite.config.js` file diff --git a/packages/vite-plugin/src/index.ts b/packages/vite-plugin/src/index.ts index 1dd2cb99..ce7f85ef 100644 --- a/packages/vite-plugin/src/index.ts +++ b/packages/vite-plugin/src/index.ts @@ -119,7 +119,7 @@ export function vanillaExtractPlugin({ async buildStart() { if (mode !== 'transform') { const { loadConfigFromFile } = await vitePromise; - const configFile = await loadConfigFromFile( + const loadedConfigFile = await loadConfigFromFile( { command: config.command, mode: config.mode, @@ -128,13 +128,18 @@ export function vanillaExtractPlugin({ config.configFile, ); + // Fall back to the resolved config if we couldn't load one. This occurs in frameworks + // that use vite but do not use a vite.config.js file. + const compilerViteConfig = loadedConfigFile?.config || config; + compiler = createCompiler({ root: config.root, identifiers: getIdentOption(), cssImportSpecifier: fileIdToVirtualId, + // @ts-expect-error Type of `assetsInclude` do not line up viteConfig: { - ...configFile?.config, - plugins: configFile?.config.plugins?.flat().filter( + ...compilerViteConfig, + plugins: compilerViteConfig.plugins?.flat().filter( (plugin) => typeof plugin === 'object' && plugin !== null &&