Skip to content

Commit

Permalink
lazy load Vite to avoid the CJS warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mrm007 committed Dec 27, 2023
1 parent e6416a8 commit 02a08ce
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<string, string>();

const hasEmitCssOverride = typeof emitCssInSsr === 'boolean';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 02a08ce

Please sign in to comment.