Skip to content

Commit

Permalink
feat: supplementary documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
HcySunYang committed Feb 14, 2020
1 parent d903374 commit 8119437
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/write-plugin.md
Expand Up @@ -79,6 +79,20 @@ module.exports = (api) => {

In most cases, you may need to customize the server. For custom server you can read: [Custom Server](/custom-server.html#connect). When customizing the server, you don't need to register the middleware as a plugin, because you can use the middleware directly in your custom `Server`.

In addition to registering `before:render` and `after:render` middleware, you can also register `before:setup` and `after:setup` middleware. The difference is that they are executed in a different order, as follows:

```js
// Execute from top to bottom
before:setup
before:render
after:render
after:setup
```

:::tip
Middleware types `before:setup` and `after:setup` are only available in `@vapper/core@1.3.0+` versions.
:::

## Register command

A new `CLI` command can be registered via the plugin, and the `module.exports.CLI` function needs to be exported in the plugin module:
Expand Down Expand Up @@ -365,6 +379,16 @@ Resolve the path based on the `output.path` of webpack
api.resolveOut('./foo.js') // /Users/work/my-project/dist/foo.js
```

### api.chainWebpack() <Badge text="1.3.0+"/>

Register a function to modify the `webpack` configuration. This function receives a `ChainableConfig` instance([webpack-chain](https://github.com/neutrinojs/webpack-chain)) as a parameter:

```js
api.chainWebpack(config => {
// ...
})
```

### api.use()

Register a `Server` middleware:
Expand Down
24 changes: 24 additions & 0 deletions docs/zh/write-plugin.md
Expand Up @@ -79,6 +79,20 @@ module.exports = (api) => {

大多数情况下,你可能需要自定义服务器,关于自定义服务器的内容可以阅读:[自定义 Server](/zh/custom-server.html#connect)。当自定义服务器时,你不需要以插件的形式注册中间件,因为你可以直接在你的自定义 `Server` 中使用相应的中间件即可。

除了可以注册 `before:render``after:render` 类型的中间件外,还可以注册 `before:setup` 以及 `after:setup` 类型的中间件,它们的不同在于执行顺序,完整的执行顺序如下:

```js
// 从上到下依次执行
before:setup
before:render
after:render
after:setup
```

:::tip
`before:setup``after:setup` 类型的中间件仅在 `@vapper/core@1.3.0+` 版本中可用。
:::

## 注册命令

通过插件可以注册新的 `CLI` 命令,需要在插件模块导出 `module.exports.CLI` 函数:
Expand Down Expand Up @@ -365,6 +379,16 @@ api.resolveCWD('./foo.js') // /Users/work/foo.js
api.resolveOut('./foo.js') // /Users/work/my-project/dist/foo.js
```

### api.chainWebpack() <Badge text="1.3.0+"/>

注册用于修改 `webpack` 配置的函数,该函数接收 `ChainableConfig` 实例([webpack-chain](https://github.com/neutrinojs/webpack-chain))作为参数:

```js
api.chainWebpack(config => {
// ...
})
```

### api.use()

注册 `Server` 中间件:
Expand Down

0 comments on commit 8119437

Please sign in to comment.