From 02a08ce514c5cff3763c3d2a6f1bf965c5ec26ee Mon Sep 17 00:00:00 2001 From: Remus Mate Date: Thu, 28 Dec 2023 00:45:53 +1100 Subject: [PATCH] lazy load Vite to avoid the CJS warning --- packages/vite-plugin/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vite-plugin/src/index.ts b/packages/vite-plugin/src/index.ts index 6a807fc2d..21d3c39e6 100644 --- a/packages/vite-plugin/src/index.ts +++ b/packages/vite-plugin/src/index.ts @@ -1,7 +1,6 @@ import path from 'path'; import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'; -import { normalizePath } from 'vite'; import outdent from 'outdent'; import { cssFileFilter, @@ -33,6 +32,8 @@ export function vanillaExtractPlugin({ let config: ResolvedConfig; let server: ViteDevServer; let postCssConfig: PostCSSConfigResult | null; + // We lazily load this utility from Vite + let normalizePath: (fsPath: string) => string; const cssMap = new Map(); const hasEmitCssOverride = typeof emitCssInSsr === 'boolean'; @@ -68,6 +69,7 @@ export function vanillaExtractPlugin({ async configResolved(resolvedConfig) { config = resolvedConfig; packageName = getPackageInfo(config.root).name; + normalizePath = (await import('vite')).normalizePath; if (config.command === 'serve') { postCssConfig = await resolvePostcssConfig(config);