From c4eff7517555764ea7e6d4043fbf34fd8eb7c304 Mon Sep 17 00:00:00 2001 From: dream2023 <1098626505@qq.com> Date: Tue, 6 Feb 2024 21:23:58 +0800 Subject: [PATCH] fix: bug --- Dockerfile | 2 +- packages/core/app/client/.umirc.ts | 1 + packages/core/build/src/build.ts | 6 ++++-- packages/core/build/src/buildClient.ts | 4 ++-- packages/core/build/src/buildPlugin.ts | 6 +++--- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index a445f6d0f6..5d5fbf1a76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN cd /tmp && \ NEWVERSION="$(cat lerna.json | jq '.version' | tr -d '"').$(date +'%Y%m%d%H%M%S')" \ && tmp=$(mktemp) \ && jq ".version = \"${NEWVERSION}\"" lerna.json > "$tmp" && mv "$tmp" lerna.json -RUN yarn install && yarn build --no-dts --sourcemap +RUN yarn install && yarn build --no-dts --sourcemap --development RUN git checkout -b release-$(date +'%Y%m%d%H%M%S') \ && yarn version:alpha -y diff --git a/packages/core/app/client/.umirc.ts b/packages/core/app/client/.umirc.ts index 1b0cd40bd5..575d173e73 100644 --- a/packages/core/app/client/.umirc.ts +++ b/packages/core/app/client/.umirc.ts @@ -18,6 +18,7 @@ indexGenerator.generate(); export default defineConfig({ title: 'Loading...', + devtool: process.env['sourcemap'] ? 'source-map' : false, favicons: ['/favicon/favicon.ico'], metas: [{ name: 'viewport', content: 'initial-scale=0.1' }], links: [ diff --git a/packages/core/build/src/build.ts b/packages/core/build/src/build.ts index 201ff256fc..b8f625c95d 100755 --- a/packages/core/build/src/build.ts +++ b/packages/core/build/src/build.ts @@ -20,7 +20,8 @@ import { Package } from '@lerna/package'; import { tarPlugin } from './tarPlugin' export async function build(pkgs: string[]) { - process.env.NODE_ENV = 'production'; + const isDev = process.argv.includes('--development'); + process.env.NODE_ENV = isDev ? 'development' : 'production'; const packages = getPackages(pkgs); if (packages.length === 0) { @@ -135,7 +136,8 @@ function runScript(args: string[], cwd: string, envs: Record = { env: { ...process.env, ...envs, - NODE_ENV: 'production', + sourcemap: process.argv.includes('--sourcemap') ? 'sourcemap' : undefined, + NODE_ENV: process.env.NODE_ENV || 'production', }, }); } diff --git a/packages/core/build/src/buildClient.ts b/packages/core/build/src/buildClient.ts index 3d30ff28a1..ce0faa4f48 100644 --- a/packages/core/build/src/buildClient.ts +++ b/packages/core/build/src/buildClient.ts @@ -32,9 +32,9 @@ export function buildEsm(cwd: string, userConfig: UserConfig, sourcemap: boolean const outDir = path.resolve(cwd, 'es'); return viteBuild( userConfig.modifyViteConfig({ - mode: 'development', + mode: process.env.NODE_ENV || 'production', define: { - 'process.env.NODE_ENV': JSON.stringify('development'), + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'), 'process.env.__TEST__': false, 'process.env.__E2E__': process.env.__E2E__ ? true : false, }, diff --git a/packages/core/build/src/buildPlugin.ts b/packages/core/build/src/buildPlugin.ts index ae98315140..1676a50a38 100644 --- a/packages/core/build/src/buildPlugin.ts +++ b/packages/core/build/src/buildPlugin.ts @@ -310,15 +310,15 @@ export async function buildPluginClient(cwd: string, userConfig: UserConfig, sou const outputFileName = 'index.js'; await viteBuild(userConfig.modifyViteConfig({ - mode: 'development', + mode: process.env.NODE_ENV || 'production', define: { - 'process.env.NODE_ENV': JSON.stringify('development'), + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'), 'process.env.__TEST__': false, 'process.env.__E2E__': process.env.__E2E__ ? true : false, }, logLevel: 'warn', build: { - minify: true, + minify: sourcemap, outDir, cssCodeSplit: false, emptyOutDir: true,