From d6805c90739086224d5bd9d5898ae7ca69dadf8c Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Mon, 30 Jan 2023 13:44:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20--prod=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=85=88=E8=AF=BB=E5=8F=96prod=E5=90=8E=E7=BC=80?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/mp/paths.js | 2 +- lib/build.js | 8 +++++--- lib/index.js | 1 + scripts/build-mp.js | 4 ++++ src/build.ts | 8 +++++--- src/index.ts | 1 + 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/config/mp/paths.js b/config/mp/paths.js index db673fd..9aa5396 100644 --- a/config/mp/paths.js +++ b/config/mp/paths.js @@ -17,7 +17,7 @@ let moduleFileExtensions = [ 'mp.ts', 'ts', ]; -if (process.env.NODE_ENV !== 'production') { +if (process.env.NODE_ENV !== 'production' && process.env.PROD !== 'true') { moduleFileExtensions = [ 'dev.mp.js', 'dev.mp.ts', diff --git a/lib/build.js b/lib/build.js index fc5143f..7250430 100644 --- a/lib/build.js +++ b/lib/build.js @@ -11,7 +11,7 @@ async function build(cmd) { //ts类型检查 waring 还是error, //主要web受影响,error级别的话 控制台和网页都报错,warning级别的话 控制台报错 const TSC_COMPILE_ON_ERROR = cmd.check !== 'error'; - (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`build ${cmd.target} environment: ${cmd.mode}`)}`); + (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`build ${cmd.target} environment: ${cmd.mode} prod: ${!!cmd.prod}`)}`); if (cmd.target === 'mp' || cmd.target === 'wechatMp') { const result = cross_spawn_1.default.sync( `cross-env`, @@ -20,8 +20,9 @@ async function build(cmd) { `NODE_TARGET=${cmd.target}`, `SUB_DIR_NAME=${cmd.subDir || 'wechatMp'}`, `TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR}`, - `COMPILE_ANALYZE=${cmd.analyze}`, + `COMPILE_ANALYZE=${!!cmd.analyze}`, `GENERATE_SOURCEMAP=${!!cmd.sourcemap}`, + `PROD=${!!cmd.prod}`, `node`, cmd.memoryLimit && `--max_old_space_size=${cmd.memoryLimit}`, require.resolve( @@ -52,8 +53,9 @@ async function build(cmd) { `NODE_TARGET=${cmd.target}`, `SUB_DIR_NAME=${cmd.subDir || 'web'}`, `TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR}`, - `COMPILE_ANALYZE=${cmd.analyze}`, + `COMPILE_ANALYZE=${!!cmd.analyze}`, `GENERATE_SOURCEMAP=${!!cmd.sourcemap}`, + `PROD=${!!cmd.prod}`, `node`, cmd.memoryLimit && `--max_old_space_size=${cmd.memoryLimit}`, require.resolve( diff --git a/lib/index.js b/lib/index.js index e24daee..27b5958 100755 --- a/lib/index.js +++ b/lib/index.js @@ -48,6 +48,7 @@ commander_1.default .command('start') .option('--sourceMap', 'sourceMap') .option('--analyze', 'analyze') + .option('--prod', 'prod') .option('--memoryLimit ', 'memoryLimit of node') .option('-t, --target ', 'target') .option('-m, --mode ', 'mode') diff --git a/scripts/build-mp.js b/scripts/build-mp.js index 450986a..97d2715 100644 --- a/scripts/build-mp.js +++ b/scripts/build-mp.js @@ -12,6 +12,10 @@ const env = getClientEnvironment(); fs.emptyDirSync(paths.appBuild); +//copy +const { copyLocaleFiles } = require('./locales/copy-mp-locales'); +copyLocaleFiles(); + webpack(config, (err, stats) => { if (err) { console.log(chalk.red(err.stack || err)); diff --git a/src/build.ts b/src/build.ts index 338d1ed..4091e7d 100644 --- a/src/build.ts +++ b/src/build.ts @@ -21,7 +21,7 @@ export default async function build(cmd: any) { //ts类型检查 waring 还是error, //主要web受影响,error级别的话 控制台和网页都报错,warning级别的话 控制台报错 const TSC_COMPILE_ON_ERROR = cmd.check !== 'error'; - Success(`${success(`build ${cmd.target} environment: ${cmd.mode}`)}`); + Success(`${success(`build ${cmd.target} environment: ${cmd.mode} prod: ${!!cmd.prod}`)}`); if (cmd.target === 'mp' || cmd.target === 'wechatMp') { const result = spawn.sync( `cross-env`, @@ -30,8 +30,9 @@ export default async function build(cmd: any) { `NODE_TARGET=${cmd.target}`, `SUB_DIR_NAME=${cmd.subDir || 'wechatMp'}`, `TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR}`, - `COMPILE_ANALYZE=${cmd.analyze}`, + `COMPILE_ANALYZE=${!!cmd.analyze}`, `GENERATE_SOURCEMAP=${!!cmd.sourcemap}`, + `PROD=${!!cmd.prod}`, `node`, require.resolve( `../scripts/${ @@ -59,8 +60,9 @@ export default async function build(cmd: any) { `NODE_TARGET=${cmd.target}`, `SUB_DIR_NAME=${cmd.subDir || 'web'}`, `TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR}`, - `COMPILE_ANALYZE=${cmd.analyze}`, + `COMPILE_ANALYZE=${!!cmd.analyze}`, `GENERATE_SOURCEMAP=${!!cmd.sourcemap}`, + `PROD=${!!cmd.prod}`, `node`, require.resolve( `../scripts/${ diff --git a/src/index.ts b/src/index.ts index e335a28..d1a82ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,7 @@ program .command('start') .option('--sourceMap', 'sourceMap') .option('--analyze', 'analyze') + .option('--prod', 'prod') .option('--memoryLimit ', 'memoryLimit of node') .option('-t, --target ', 'target') .option('-m, --mode ', 'mode') From 5a46313af651d0b63f85453ba3e37bade9de0d20 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Mon, 30 Jan 2023 13:59:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A8=A1=E7=89=88=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20start:web:prod=E5=92=8Cstart:mp:prod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/template.js | 2 ++ src/template.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/template.js b/lib/template.js index 152a8b2..a7b1667 100644 --- a/lib/template.js +++ b/lib/template.js @@ -33,9 +33,11 @@ function packageJsonContent({ name, version, description, cliVersion, cliName, c "scripts": { "make:domain": "${cliBinName} make", "start:mp": "${cliBinName} start --target mp --mode development", + "start:mp:prod": "${cliBinName} start --target mp --mode development --prod", "build:mp": "${cliBinName} build --target mp --mode production", "build-analyze:mp": "${cliBinName} build --target mp --mode production --analyze", "start:web": "${cliBinName} start --target web --mode development", + "start:web:prod": "${cliBinName} start --target web --mode development --prod", "build:web": "${cliBinName} build --target web --mode production", "build-analyze:web": "${cliBinName} build --target web --mode production --analyze", "build-sourcemap-analyze:web": "${cliBinName} build --target web --mode production --sourcemap --analyze", diff --git a/src/template.ts b/src/template.ts index a2f9ef5..fc9f2a3 100644 --- a/src/template.ts +++ b/src/template.ts @@ -40,9 +40,11 @@ export function packageJsonContent({ "scripts": { "make:domain": "${cliBinName} make", "start:mp": "${cliBinName} start --target mp --mode development", + "start:mp:prod": "${cliBinName} start --target mp --mode development --prod", "build:mp": "${cliBinName} build --target mp --mode production", "build-analyze:mp": "${cliBinName} build --target mp --mode production --analyze", "start:web": "${cliBinName} start --target web --mode development", + "start:web:prod": "${cliBinName} start --target web --mode development --prod", "build:web": "${cliBinName} build --target web --mode production", "build-analyze:web": "${cliBinName} build --target web --mode production --analyze", "build-sourcemap-analyze:web": "${cliBinName} build --target web --mode production --sourcemap --analyze", From 27b5d24ffcac1635ea6d974d382b6e5343c2b886 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Mon, 30 Jan 2023 14:00:46 +0800 Subject: [PATCH 3/3] web paths --- config/web/paths.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/config/web/paths.js b/config/web/paths.js index 04d3aa1..514f634 100644 --- a/config/web/paths.js +++ b/config/web/paths.js @@ -40,7 +40,7 @@ let moduleFileExtensions = [ 'pc.jsx', 'jsx', ]; -if (process.env.NODE_ENV !== 'production') { +if (process.env.NODE_ENV !== 'production' && process.env.PROD !== 'true') { moduleFileExtensions = [ 'dev.web.js', 'dev.web.ts', @@ -49,16 +49,15 @@ if (process.env.NODE_ENV !== 'production') { 'dev.ts', 'dev.tsx', ].concat(moduleFileExtensions); -} -else { - moduleFileExtensions = [ - 'prod.web.js', - 'prod.web.ts', - 'prod.web.tsx', - 'prod.js', - 'prod.ts', - 'prod.tsx', - ].concat(moduleFileExtensions); +} else { + moduleFileExtensions = [ + 'prod.web.js', + 'prod.web.ts', + 'prod.web.tsx', + 'prod.js', + 'prod.ts', + 'prod.tsx', + ].concat(moduleFileExtensions); } // Resolve file paths in the same order as webpack