支持 -subDir

This commit is contained in:
Wang Kejun 2022-07-06 14:25:01 +08:00
parent 7999b13872
commit e79b4e6f1b
7 changed files with 44 additions and 10 deletions

View File

@ -3,10 +3,11 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const subDirName = process.env.SUB_DIR_NAME || 'wechatMp';
const appDirectory = fs.realpathSync(process.cwd()); const appDirectory = fs.realpathSync(process.cwd());
const resolveRoot = (relativePath) => path.resolve(appDirectory, relativePath); 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'; const buildPath = process.env.BUILD_PATH || 'dist';

View File

@ -3,12 +3,13 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath'); 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: // Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637 // https://github.com/facebook/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd()); const appDirectory = fs.realpathSync(process.cwd());
const resolveRoot = (relativePath) => path.resolve(appDirectory, relativePath); 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 // We use `PUBLIC_URL` environment variable or "homepage" field to infer
// "public path" at which the app is served. // "public path" at which the app is served.

View File

@ -644,8 +644,12 @@ module.exports = function (webpackEnv) {
}, },
'less-loader', 'less-loader',
{ {
lessOptions: { lessOptions: () => {
javascriptEnabled: true, const oakConfigJson = require(paths.oakConfigJson);
return {
javascriptEnabled: true,
modifyVars: oakConfigJson.theme,
};
}, },
} }
), ),
@ -666,8 +670,12 @@ module.exports = function (webpackEnv) {
}, },
'less-loader', 'less-loader',
{ {
lessOptions: { lessOptions: () => {
javascriptEnabled: true, const oakConfigJson = require(paths.oakConfigJson);
return {
javascriptEnabled: true,
modifyVars: oakConfigJson.theme,
};
}, },
} }
), ),

View File

@ -15,7 +15,12 @@ async function build(cmd) {
const TSC_COMPILE_ON_ERROR = cmd.check !== 'error'; 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}`)}`);
if (cmd.target === 'mp' || cmd.target === 'wechatMp') { 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' require.resolve(`../scripts/${cmd.mode === 'production'
? 'build-mp.js' ? 'build-mp.js'
: 'start-mp.js'}`), : 'start-mp.js'}`),
@ -31,7 +36,12 @@ async function build(cmd) {
} }
} }
else if (cmd.target === 'web') { 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' require.resolve(`../scripts/${cmd.mode === 'production'
? 'build-web.js' ? 'build-web.js'
: 'start-web.js'}`), : 'start-web.js'}`),

View File

@ -50,6 +50,7 @@ commander_1.default
.command('start') .command('start')
.option('-t, --target <target>', 'target') .option('-t, --target <target>', 'target')
.option('-m, --mode <mode>', 'mode') .option('-m, --mode <mode>', 'mode')
.option('-d, --subDir <subDirName>', 'subDirName')
.option('-c, --check <level>', 'level') .option('-c, --check <level>', 'level')
.description('build project of start on demand') .description('build project of start on demand')
.action(build_1.default); .action(build_1.default);
@ -57,6 +58,7 @@ commander_1.default
.command('build') .command('build')
.option('-t, --target <target>', 'target') .option('-t, --target <target>', 'target')
.option('-m, --mode <mode>', 'mode') .option('-m, --mode <mode>', 'mode')
.option('-d, --subDir <subDirName>', 'subDirName')
.option('-c, --check <level>', 'level') .option('-c, --check <level>', 'level')
.description('build project of build on demand') .description('build project of build on demand')
.action(build_1.default); .action(build_1.default);

View File

@ -24,8 +24,13 @@ export default async function build(cmd: any) {
Success(`${success(`build ${cmd.target} environment: ${cmd.mode}`)}`); Success(`${success(`build ${cmd.target} environment: ${cmd.mode}`)}`);
if (cmd.target === 'mp' || cmd.target === 'wechatMp') { if (cmd.target === 'mp' || cmd.target === 'wechatMp') {
const result = spawn.sync( 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( require.resolve(
`../scripts/${ `../scripts/${
cmd.mode === 'production' cmd.mode === 'production'
@ -46,8 +51,13 @@ export default async function build(cmd: any) {
} }
} else if (cmd.target === 'web') { } else if (cmd.target === 'web') {
const result = spawn.sync( 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( require.resolve(
`../scripts/${ `../scripts/${
cmd.mode === 'production' cmd.mode === 'production'

View File

@ -52,6 +52,7 @@ program
.command('start') .command('start')
.option('-t, --target <target>', 'target') .option('-t, --target <target>', 'target')
.option('-m, --mode <mode>', 'mode') .option('-m, --mode <mode>', 'mode')
.option('-d, --subDir <subDirName>', 'subDirName')
.option('-c, --check <level>', 'level') .option('-c, --check <level>', 'level')
.description('build project of start on demand') .description('build project of start on demand')
.action(build); .action(build);
@ -59,6 +60,7 @@ program
.command('build') .command('build')
.option('-t, --target <target>', 'target') .option('-t, --target <target>', 'target')
.option('-m, --mode <mode>', 'mode') .option('-m, --mode <mode>', 'mode')
.option('-d, --subDir <subDirName>', 'subDirName')
.option('-c, --check <level>', 'level') .option('-c, --check <level>', 'level')
.description('build project of build on demand') .description('build project of build on demand')
.action(build); .action(build);