diff --git a/.changeset/modern-schools-tan.md b/.changeset/modern-schools-tan.md new file mode 100644 index 000000000..e15ed781d --- /dev/null +++ b/.changeset/modern-schools-tan.md @@ -0,0 +1,5 @@ +--- +'@vanilla-extract/vite-plugin': minor +--- + +Add `viteConfigOverrides` option diff --git a/packages/vite-plugin/package.json b/packages/vite-plugin/package.json index 24b86825b..2a93477a8 100644 --- a/packages/vite-plugin/package.json +++ b/packages/vite-plugin/package.json @@ -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" diff --git a/packages/vite-plugin/src/index.ts b/packages/vite-plugin/src/index.ts index 54fbb7bd8..a18c2e4a7 100644 --- a/packages/vite-plugin/src/index.ts +++ b/packages/vite-plugin/src/index.ts @@ -18,6 +18,7 @@ import { createCompiler, normalizePath, } from '@vanilla-extract/integration'; +import deepmerge from 'deepmerge'; const virtualExtCss = '.vanilla.css'; @@ -45,10 +46,12 @@ const removeIncompatiblePlugins = (plugin: PluginOption) => interface Options { identifiers?: IdentifierOption; unstable_mode?: 'transform' | 'emitCss'; + viteConfigOverrides?: Partial; } export function vanillaExtractPlugin({ identifiers, unstable_mode: mode = 'emitCss', + viteConfigOverrides = {}, }: Options = {}): Plugin { let config: ResolvedConfig; let configEnv: ConfigEnv; @@ -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, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 63317a282..cc252faa5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -578,6 +578,9 @@ importers: '@vanilla-extract/integration': specifier: workspace:^ version: link:../integration + deepmerge: + specifier: ^4.3.1 + version: 4.3.1 devDependencies: vite: specifier: ^5.0.11 @@ -5323,6 +5326,10 @@ packages: resolution: {integrity: sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==} engines: {node: '>=0.10.0'} + deepmerge@4.3.1: + resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} + engines: {node: '>=0.10.0'} + default-browser-id@5.0.0: resolution: {integrity: sha512-A6p/pu/6fyBcA1TRz/GqWYPViplrftcW2gZC9q79ngNCKAeR/X3gcEdXQHl4KNXV+3wgIJ1CPkJQ3IHM6lcsyA==} engines: {node: '>=18'} @@ -13418,7 +13425,7 @@ snapshots: dependencies: chalk: 5.0.1 cron-parser: 4.6.0 - deepmerge: 4.2.2 + deepmerge: 4.3.1 dot-prop: 7.2.0 execa: 6.1.0 fast-safe-stringify: 2.1.1 @@ -14766,7 +14773,7 @@ snapshots: '@rollup/pluginutils': 3.1.0(rollup@2.79.1) '@types/resolve': 1.17.1 builtin-modules: 3.3.0 - deepmerge: 4.2.2 + deepmerge: 4.3.1 is-module: 1.0.0 resolve: 1.22.8 rollup: 2.79.1 @@ -15337,7 +15344,7 @@ snapshots: csstype: 3.0.10 dedent: 1.5.3 deep-object-diff: 1.1.9 - deepmerge: 4.2.2 + deepmerge: 4.3.1 media-query-parser: 2.0.2 modern-ahocorasick: 1.0.0 picocolors: 1.0.0 @@ -16985,6 +16992,8 @@ snapshots: deepmerge@4.2.2: {} + deepmerge@4.3.1: {} + default-browser-id@5.0.0: {} default-browser@5.2.1: @@ -19190,7 +19199,7 @@ snapshots: babel-jest: 29.7.0(@babel/core@7.23.9) chalk: 4.1.2 ci-info: 3.9.0 - deepmerge: 4.2.2 + deepmerge: 4.3.1 glob: 7.2.0 graceful-fs: 4.2.10 jest-circus: 29.7.0