Skip to content

Commit

Permalink
vite: allow passing overrides for vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
XiNiHa committed Jul 7, 2024
1 parent 28df959 commit 8501f33
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"author": "SEEK",
"license": "MIT",
"dependencies": {
"@vanilla-extract/integration": "workspace:^"
"@vanilla-extract/integration": "workspace:^",
"deepmerge": "^4.3.1"
},
"devDependencies": {
"vite": "^5.0.11"
Expand Down
18 changes: 12 additions & 6 deletions packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
createCompiler,
normalizePath,
} from '@vanilla-extract/integration';
import deepmerge from 'deepmerge';

const virtualExtCss = '.vanilla.css';

Expand Down Expand Up @@ -45,10 +46,12 @@ const removeIncompatiblePlugins = (plugin: PluginOption) =>
interface Options {
identifiers?: IdentifierOption;
unstable_mode?: 'transform' | 'emitCss';
viteConfigOverrides?: Partial<UserConfig>;
}
export function vanillaExtractPlugin({
identifiers,
unstable_mode: mode = 'emitCss',
viteConfigOverrides = {},
}: Options = {}): Plugin {
let config: ResolvedConfig;
let configEnv: ConfigEnv;
Expand Down Expand Up @@ -142,12 +145,15 @@ export function vanillaExtractPlugin({
configForViteCompiler = config.inlineConfig;
}

const viteConfig = {
...configForViteCompiler,
plugins: configForViteCompiler?.plugins
?.flat()
.filter(removeIncompatiblePlugins),
};
const viteConfig = deepmerge(
{
...configForViteCompiler,
plugins: configForViteCompiler?.plugins
?.flat()
.filter(removeIncompatiblePlugins),
},
viteConfigOverrides,
);

compiler = createCompiler({
root: config.root,
Expand Down
17 changes: 13 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8501f33

Please sign in to comment.