From e79b4e6f1b7fc42e45046d22bacbb087ba43b345 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Wed, 6 Jul 2022 14:25:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=20-subDir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/mp/paths.js | 3 ++- config/web/paths.js | 3 ++- config/web/webpack.config.js | 16 ++++++++++++---- lib/build.js | 14 ++++++++++++-- lib/index.js | 2 ++ src/build.ts | 14 ++++++++++++-- src/index.ts | 2 ++ 7 files changed, 44 insertions(+), 10 deletions(-) diff --git a/config/mp/paths.js b/config/mp/paths.js index c4b1d0d..a0a5de7 100644 --- a/config/mp/paths.js +++ b/config/mp/paths.js @@ -3,10 +3,11 @@ const path = require('path'); const fs = require('fs'); +const subDirName = process.env.SUB_DIR_NAME || 'wechatMp'; const appDirectory = fs.realpathSync(process.cwd()); const resolveRoot = (relativePath) => path.resolve(appDirectory, relativePath); -const resolveApp = (relativePath) => path.resolve(resolveRoot('wechatMp'), relativePath); +const resolveApp = (relativePath) => path.resolve(resolveRoot(subDirName), relativePath); const buildPath = process.env.BUILD_PATH || 'dist'; diff --git a/config/web/paths.js b/config/web/paths.js index bb4ae1f..dc80729 100644 --- a/config/web/paths.js +++ b/config/web/paths.js @@ -3,12 +3,13 @@ const path = require('path'); const fs = require('fs'); const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath'); +const subDirName = process.env.SUB_DIR_NAME || 'web'; // Make sure any symlinks in the project folder are resolved: // https://github.com/facebook/create-react-app/issues/637 const appDirectory = fs.realpathSync(process.cwd()); const resolveRoot = (relativePath) => path.resolve(appDirectory, relativePath); -const resolveApp = (relativePath) => path.resolve(resolveRoot('web'), relativePath); +const resolveApp = (relativePath) => path.resolve(resolveRoot(subDirName), relativePath); // We use `PUBLIC_URL` environment variable or "homepage" field to infer // "public path" at which the app is served. diff --git a/config/web/webpack.config.js b/config/web/webpack.config.js index 68bd8bb..04e08be 100644 --- a/config/web/webpack.config.js +++ b/config/web/webpack.config.js @@ -644,8 +644,12 @@ module.exports = function (webpackEnv) { }, 'less-loader', { - lessOptions: { - javascriptEnabled: true, + lessOptions: () => { + const oakConfigJson = require(paths.oakConfigJson); + return { + javascriptEnabled: true, + modifyVars: oakConfigJson.theme, + }; }, } ), @@ -666,8 +670,12 @@ module.exports = function (webpackEnv) { }, 'less-loader', { - lessOptions: { - javascriptEnabled: true, + lessOptions: () => { + const oakConfigJson = require(paths.oakConfigJson); + return { + javascriptEnabled: true, + modifyVars: oakConfigJson.theme, + }; }, } ), diff --git a/lib/build.js b/lib/build.js index dc9c9b3..1878ff6 100644 --- a/lib/build.js +++ b/lib/build.js @@ -15,7 +15,12 @@ async function build(cmd) { const TSC_COMPILE_ON_ERROR = cmd.check !== 'error'; (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`build ${cmd.target} environment: ${cmd.mode}`)}`); if (cmd.target === 'mp' || cmd.target === 'wechatMp') { - const result = cross_spawn_1.default.sync(`cross-env NODE_ENV=${cmd.mode} NODE_TARGET=${cmd.target} TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR} "${process.execPath}"`, [ + const result = cross_spawn_1.default.sync(`cross-env`, [ + `NODE_ENV=${cmd.mode}`, + `NODE_TARGET=${cmd.target}`, + `SUB_DIR_NAME=${cmd.subDir || 'wechatMp'}`, + `TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR}`, + `"${process.execPath}"`, require.resolve(`../scripts/${cmd.mode === 'production' ? 'build-mp.js' : 'start-mp.js'}`), @@ -31,7 +36,12 @@ async function build(cmd) { } } else if (cmd.target === 'web') { - const result = cross_spawn_1.default.sync(`cross-env NODE_ENV=${cmd.mode} NODE_TARGET=${cmd.target} TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR} "${process.execPath}"`, [ + const result = cross_spawn_1.default.sync(`cross-env`, [ + `NODE_ENV=${cmd.mode}`, + `NODE_TARGET=${cmd.target}`, + `SUB_DIR_NAME=${cmd.subDir || 'web'}`, + `TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR}`, + `"${process.execPath}"`, require.resolve(`../scripts/${cmd.mode === 'production' ? 'build-web.js' : 'start-web.js'}`), diff --git a/lib/index.js b/lib/index.js index cf4599f..d9f538f 100755 --- a/lib/index.js +++ b/lib/index.js @@ -50,6 +50,7 @@ commander_1.default .command('start') .option('-t, --target ', 'target') .option('-m, --mode ', 'mode') + .option('-d, --subDir ', 'subDirName') .option('-c, --check ', 'level') .description('build project of start on demand') .action(build_1.default); @@ -57,6 +58,7 @@ commander_1.default .command('build') .option('-t, --target ', 'target') .option('-m, --mode ', 'mode') + .option('-d, --subDir ', 'subDirName') .option('-c, --check ', 'level') .description('build project of build on demand') .action(build_1.default); diff --git a/src/build.ts b/src/build.ts index 4580122..9e1cebe 100644 --- a/src/build.ts +++ b/src/build.ts @@ -24,8 +24,13 @@ export default async function build(cmd: any) { Success(`${success(`build ${cmd.target} environment: ${cmd.mode}`)}`); if (cmd.target === 'mp' || cmd.target === 'wechatMp') { const result = spawn.sync( - `cross-env NODE_ENV=${cmd.mode} NODE_TARGET=${cmd.target} TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR} "${process.execPath}"`, + `cross-env`, [ + `NODE_ENV=${cmd.mode}`, + `NODE_TARGET=${cmd.target}`, + `SUB_DIR_NAME=${cmd.subDir || 'wechatMp'}`, + `TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR}`, + `"${process.execPath}"`, require.resolve( `../scripts/${ cmd.mode === 'production' @@ -46,8 +51,13 @@ export default async function build(cmd: any) { } } else if (cmd.target === 'web') { const result = spawn.sync( - `cross-env NODE_ENV=${cmd.mode} NODE_TARGET=${cmd.target} TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR} "${process.execPath}"`, + `cross-env`, [ + `NODE_ENV=${cmd.mode}`, + `NODE_TARGET=${cmd.target}`, + `SUB_DIR_NAME=${cmd.subDir || 'web'}`, + `TSC_COMPILE_ON_ERROR=${TSC_COMPILE_ON_ERROR}`, + `"${process.execPath}"`, require.resolve( `../scripts/${ cmd.mode === 'production' diff --git a/src/index.ts b/src/index.ts index 9876a5e..16f3758 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,7 @@ program .command('start') .option('-t, --target ', 'target') .option('-m, --mode ', 'mode') + .option('-d, --subDir ', 'subDirName') .option('-c, --check ', 'level') .description('build project of start on demand') .action(build); @@ -59,6 +60,7 @@ program .command('build') .option('-t, --target ', 'target') .option('-m, --mode ', 'mode') + .option('-d, --subDir ', 'subDirName') .option('-c, --check ', 'level') .description('build project of build on demand') .action(build);