From 48532ed26717115886cd4a89616f7ae6fe45dbad Mon Sep 17 00:00:00 2001 From: sunhao Date: Thu, 27 Jun 2019 16:42:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=20=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=85=8D=E7=BD=AE=E7=AB=AF=E5=8F=A3=E5=8F=B7?= =?UTF-8?q?=20=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @types/index.d.ts | 2 +- doc/build.config.ts | 3 +++ src/utils/index.ts | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/@types/index.d.ts b/@types/index.d.ts index 32c9be0..b800c67 100644 --- a/@types/index.d.ts +++ b/@types/index.d.ts @@ -269,7 +269,7 @@ declare namespace build { /** * build 通用 webpack 配置 */ - interface options extends BuildService.serverInitOptions { + interface options extends BuildService.serverInitOptions, BuildService.parsedArgs.serverStart { /** * 当前程序运行版本 */ diff --git a/doc/build.config.ts b/doc/build.config.ts index 5c3ed22..0126ff8 100644 --- a/doc/build.config.ts +++ b/doc/build.config.ts @@ -15,8 +15,11 @@ export default function(inject: ConfigOptions.getOptionsInject): ConfigOptions.o const client: any = getClient(config, inject) const server: any = getServer(config, inject) + const { port } = config + return { env: ['SERVER_ENV', 'ENV', 'NODE_ENV'], + port, babelrc: { presets: [ [ diff --git a/src/utils/index.ts b/src/utils/index.ts index c3d2c37..48208a1 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -158,6 +158,20 @@ async function setWebpack( process.env.PUBLIC_PATH = path return options } + +/** + * 通过 用户的设定 完善 argv参数 + * @param options build 通用 webpack 配置 + * @param argv BuildService 通用 启动参数 + */ +function completeArgvByUserConfig( + argv: BuildService.parsedArgs, + options: ConfigOptions.options +) { + if (!argv.port) argv.port = options.port + if (!argv.fileDescriptor) argv.fileDescriptor = options.fileDescriptor + return argv +} /** * 设置 静态文件后缀 * @param options build 通用 webpack 配置 @@ -284,6 +298,8 @@ export async function initConfig( buildServiceConfig = options + argv = completeArgvByUserConfig(argv, options) + return options } /**