Skip to content

Commit

Permalink
doc: Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jan 22, 2021
1 parent e37978f commit 295ab41
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down

0 comments on commit 295ab41

Please sign in to comment.