Skip to content

Commit

Permalink
Fix propagation of the user's vite config in vite-based frameworks th…
Browse files Browse the repository at this point in the history
…at don't use a vite.config.js file
  • Loading branch information
askoufis committed Mar 23, 2024
1 parent c796ced commit eb88400
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-elephants-rest.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 8 additions & 3 deletions packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 &&
Expand Down

0 comments on commit eb88400

Please sign in to comment.