From ffc75d4b9157bf46bdfbb80962cf02a4c78d7d9a Mon Sep 17 00:00:00 2001 From: wkj <278599135@.com> Date: Mon, 16 Jun 2025 10:18:50 +0800 Subject: [PATCH] react-native ios build main.jsbundle --- src/build.ts | 101 +++++++++++++++++++++++++++++++++++---------------- src/index.ts | 2 +- 2 files changed, 71 insertions(+), 32 deletions(-) diff --git a/src/build.ts b/src/build.ts index 3bc2cea..a5912bd 100644 --- a/src/build.ts +++ b/src/build.ts @@ -132,38 +132,77 @@ export default async function build(cmd: any) { let result; if (mode === 'production') { //cd native/android && cross-env NODE_ENV=production ./gradlew assembleRelease - result = spawn.sync( - `cd android`, - [ - '&& cross-env', - `NODE_ENV=${mode}`, - 'OAK_PLATFORM=native', - `OAK_DEV_MODE=${devMode}`, - './gradlew assembleRelease', - ].filter(Boolean), - { - cwd, - stdio: 'inherit', - shell: true, - } - ); + if (platform === 'android') { + result = spawn.sync( + `cd android`, + [ + '&& cross-env', + `NODE_ENV=${mode}`, + 'OAK_PLATFORM=native', + `OAK_DEV_MODE=server`, + './gradlew assembleRelease', + ].filter(Boolean), + { + cwd, + stdio: 'inherit', + shell: true, + } + ); + } + else { + // cd native && cross-env NODE_ENV=staging OAK_PLATFORM=native OAK_DEV_MODE=server react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' + result = spawn.sync( + `cd native`, + [ + '&& cross-env', + `NODE_ENV=${mode}`, + 'OAK_PLATFORM=native', + `OAK_DEV_MODE=server`, + "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'", + ].filter(Boolean), + { + cwd, + stdio: 'inherit', + shell: true, + } + ); + } } else if (mode === 'staging') { //cd native/android && cross-env NODE_ENV=production ./gradlew assembleStaging - result = spawn.sync( - `cd android`, - [ - '&& cross-env', - `NODE_ENV=${mode}`, - 'OAK_PLATFORM=native', - `OAK_DEV_MODE=${devMode}`, - './gradlew assembleStaging', - ].filter(Boolean), - { - cwd, - stdio: 'inherit', - shell: true, - } - ); + if (platform === 'android') { + result = spawn.sync( + `cd android`, + [ + '&& cross-env', + `NODE_ENV=${mode}`, + 'OAK_PLATFORM=native', + `OAK_DEV_MODE=server`, + './gradlew assembleStaging', + ].filter(Boolean), + { + cwd, + stdio: 'inherit', + shell: true, + } + ); + } + else { + result = spawn.sync( + `cd native`, + [ + '&& cross-env', + `NODE_ENV=${mode}`, + 'OAK_PLATFORM=native', + `OAK_DEV_MODE=server`, + "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'", + ].filter(Boolean), + { + cwd, + stdio: 'inherit', + shell: true, + } + ); + } } else { result = spawn.sync( `cross-env`, @@ -173,7 +212,7 @@ export default async function build(cmd: any) { `OAK_DEV_MODE=${devMode}`, 'react-native', 'start', - cmd.resetCache && '--reset-cache', + cmd.reset && '--reset-cache', ].filter(Boolean), { cwd, diff --git a/src/index.ts b/src/index.ts index 61cbfff..3784f54 100644 --- a/src/index.ts +++ b/src/index.ts @@ -79,7 +79,7 @@ program .option('-d, --subDir ', 'subDirName') .option('-p, --port ', 'port') .option('-dm, --devMode ', 'devMode') - .option('--resetCache', 'react native start --reset-cache') + .option('--reset', 'react native start --reset-cache') .description('build project of start on demand') .action(build);