From 01703c155f0637c5b25903575ce2233a91d0ab13 Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Tue, 28 May 2024 21:16:03 +0200 Subject: [PATCH] feat(admin-sdk): Merge users Vite config (#7509) **What** - Allows users to customize the Vite config from `admin.vite` in `medusa-config.js` **How** ``` /** @type {import('@medusajs/types').ConfigModule} */ module.exports = { projectConfig, admin: { backendUrl: "http://localhost:9000", // the config param is our default config vite: (config) => { return { define: { __TEST__: JSON.stringify("test"), // this will now be defined as a const that can be accessed in widgets }, }; }, }, // ... }; ``` The `vite` param is a callback that takes our default config as a param. If the user does not need to access our config they don't have to use it, as we merge their config with our own, but accessing the default config can be useful in some cases. --- packages/admin-next/admin-sdk/src/lib/config.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/admin-next/admin-sdk/src/lib/config.ts b/packages/admin-next/admin-sdk/src/lib/config.ts index f6537d5494..8b56551ac9 100644 --- a/packages/admin-next/admin-sdk/src/lib/config.ts +++ b/packages/admin-next/admin-sdk/src/lib/config.ts @@ -8,7 +8,7 @@ import { BundlerOptions } from "../types" export async function getViteConfig( options: BundlerOptions ): Promise { - const { searchForWorkspaceRoot } = await import("vite") + const { searchForWorkspaceRoot, mergeConfig } = await import("vite") const { default: react } = await import("@vitejs/plugin-react") const { default: medusa } = await import("@medusajs/admin-vite-plugin") @@ -19,7 +19,7 @@ export async function getViteConfig( const backendUrl = options.backendUrl ?? "" - return { + const baseConfig: InlineConfig = { root, base: options.path, build: { @@ -59,6 +59,14 @@ export async function getViteConfig( }), ], } + + if (options.vite) { + const customConfig = options.vite(baseConfig) + + return mergeConfig(baseConfig, customConfig) + } + + return baseConfig } function createTailwindConfig(entry: string, sources: string[] = []) {