From 59067bef7de1d97d398834cb8e5619eccf795eaa Mon Sep 17 00:00:00 2001 From: tqma113 Date: Sat, 30 Oct 2021 07:40:54 +0800 Subject: [PATCH] feat(config): add defineConfig (#32) * feat(config): add defineConfig * docs: update defineConfig --- doc/Config/usage.md | 15 +++++++-------- src/index.ts | 4 ++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/doc/Config/usage.md b/doc/Config/usage.md index efb47237..b451002e 100644 --- a/doc/Config/usage.md +++ b/doc/Config/usage.md @@ -8,13 +8,12 @@ ```ts import path from 'path' -import { Config } from '../../src' -import cf from './config' +import { defineConfig } from 'react-imvc' let PORT = 33336 const ROOT = __dirname -const config: Config = { +const config = defineConfig({ root: ROOT, // 项目根目录 port: PORT, // server 端口号 routes: 'routes', // 服务端路由目录 @@ -25,7 +24,7 @@ const config: Config = { path: path.resolve(ROOT, '../publish/static') }, webpackDevMiddleware: true -} +}) export default config ``` @@ -52,16 +51,16 @@ export default config 启动文件中需要使用 React-IMVC 中暴露的接口启动,使用方式如下: ```ts -import start from '../../src/start' -import { Config } from '../../src/' +import { start, defineConfig } from 'react-imvc' + const PORT: number = 3333 const ROOT = __dirname -const config: Config = { +const config = defineConfig({ root: ROOT, // 项目根目录 port: PORT, // server 端口号 routes: 'routes', // 服务端路由目录 layout: 'Layout', // 自定义 Layout -} +}) async function main() { let { app, server } = await start({ config }) diff --git a/src/index.ts b/src/index.ts index 136149d5..7baaf963 100644 --- a/src/index.ts +++ b/src/index.ts @@ -506,3 +506,7 @@ export interface EntireConfig { */ entry?: string | string[] | webpack.Entry | webpack.EntryFunc } + +export const defineConfig = (config: Config): Config => { + return config +}