From 295ab41bb407e3ba1c46bd9251d70cdba8d92617 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Fri, 22 Jan 2021 18:04:47 +0800 Subject: [PATCH] doc: Update README.md --- core/README.md | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/core/README.md b/core/README.md index 293172bb..a6307d91 100644 --- a/core/README.md +++ b/core/README.md @@ -120,25 +120,23 @@ $ npm run build Supports `kktrc.js` and `kktrc.ts`. -```ts +```typescript import express from 'express'; import { ParsedArgs } from 'minimist'; -import WebpackDevServer, { Configuration } from 'webpack-dev-server'; -import { LoaderConfOptions, DevServerConfigFunction, MockerAPIOptions } from 'kkt'; +import { Configuration } from 'webpack'; +import WebpackDevServer from 'webpack-dev-server'; +import { LoaderConfOptions, MockerAPIOptions } from 'kkt'; type KKTRC = { proxySetup?: (app: express.Application) => MockerAPIOptions; - devServer?: (configFunction: DevServerConfigFunction, evn: string) => DevServerConfigFunction; + devServer?: (config: WebpackDevServer.Configuration) => WebpackDevServer.Configuration; default?: (conf: Configuration, evn: string, options: LoaderConfOptions) => Configuration; }; - -type DevServerConfigFunction = (proxy: WebpackDevServer.ProxyConfigArrayItem[], allowedHost: string) - => WebpackDevServer.Configuration; ``` Example -```ts +```typescript import webpack, { Configuration } from 'webpack'; import WebpackDevServer from 'webpack-dev-server'; import lessModules from '@kkt/less-modules'; @@ -151,25 +149,22 @@ export default (conf: Configuration, env: string, options: LoaderConfOptions) => return conf; } -export const devServer = (configFunction: DevServerConfigFunction) => { - return (proxy: WebpackDevServer.ProxyConfigArrayItem[], allowedHost: string) => { - // Create the default config by calling configFunction with the proxy/allowedHost parameters - const config = configFunction(proxy, allowedHost); - - // Change the https certificate options to match your certificate, using the .env file to - // set the file paths & passphrase. - const fs = require('fs'); - config.https = { - key: fs.readFileSync(process.env.REACT_HTTPS_KEY, 'utf8'), - cert: fs.readFileSync(process.env.REACT_HTTPS_CERT, 'utf8'), - ca: fs.readFileSync(process.env.REACT_HTTPS_CA, 'utf8'), - passphrase: process.env.REACT_HTTPS_PASS - }; - - // Return your customised Webpack Development Server config. - return config; - } -} +/** + * Modify WebpackDevServer Configuration Example + */ +export const devServer = (config: WebpackDevServer.Configuration) => { + // Change the https certificate options to match your certificate, using the .env file to + // set the file paths & passphrase. + const fs = require('fs'); + config.https = { + key: fs.readFileSync(process.env.REACT_HTTPS_KEY, 'utf8'), + cert: fs.readFileSync(process.env.REACT_HTTPS_CERT, 'utf8'), + ca: fs.readFileSync(process.env.REACT_HTTPS_CA, 'utf8'), + passphrase: process.env.REACT_HTTPS_PASS + }; + // Return your customised Webpack Development Server config. + return config; +}; // Configuring the Proxy Manually import express from 'express';