From aea7c2233967c41c3842d4d2ede91c917363e27d Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sat, 6 Aug 2022 17:35:57 +0800 Subject: [PATCH] fix(@vant/cli): should replace NODE_ENV in vite v3 --- packages/vant-cli/src/config/vite.package.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/vant-cli/src/config/vite.package.ts b/packages/vant-cli/src/config/vite.package.ts index 467416e8413..a69eb6f8443 100644 --- a/packages/vant-cli/src/config/vite.package.ts +++ b/packages/vant-cli/src/config/vite.package.ts @@ -14,12 +14,19 @@ export function getViteConfigForPackage({ const { name, build } = getVantConfig(); const entryExtension = build?.extensions?.esm || '.js'; const entry = join(ES_DIR, `index${entryExtension}`); + const shouldReplaceEnv = minify || formats?.includes('umd'); return { root: CWD, logLevel: 'silent', + define: shouldReplaceEnv + ? { + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), + } + : undefined, + build: { lib: { name, @@ -30,6 +37,7 @@ export function getViteConfigForPackage({ return minify ? `${name}${suffix}.min.js` : `${name}${suffix}.js`; }, }, + // terser has better compression than esbuild minify: minify ? 'terser' : false, rollupOptions: {