Skip to content

Commit

Permalink
docs: improve
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 24, 2024
1 parent 5326988 commit cb393de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ Notice: When using `"node"`, you also need to set `dynamicImportToRequire` to `t
Specify the plugins to use.

```ts
// JSHooks
{
name?: string;
enforce?: "pre" | "post";
Expand All @@ -583,12 +582,15 @@ Specify the plugins to use.
}
```

JSHooks is a set of hook functions used to extend the compilation process of Mako.
And you can also use this methods in hook functions.

- `name`, plugin name
- `buildStart`, called before Build starts
- `load`, used to load files, return file content and type, type supports `css`, `js`, `jsx`, `ts`, `tsx`
- `generateEnd`, called after Generate completes, `isFirstCompile` can be used to determine if it is the first compilation, `time` is the compilation time, and `stats` is the compilation statistics information
- `this.emitFile({ type: 'asset', fileName: string, source: string | Uint8Array })`, emit a file
- `this.warn(message: string)`, emit a warning
- `this.error(message: string)`, emit a error
- `this.parse(code: string)`, parse the code (CURRENTLY NOT SUPPORTED)
- `this.addWatchFile(filePath: string)`, add a watch file (CURRENTLY NOT SUPPORTED)

Plugins is compatible with [unplugin](https://unplugin.unjs.io/), so you can use plugins from unplugin like [unplugin-icons](https://github.com/unplugin/unplugin-icons), [unplugin-replace](https://github.com/unplugin/unplugin-replace) and so on.

### progress

Expand Down
14 changes: 8 additions & 6 deletions docs/config.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ import(/* webpackIgnore: true */ "./foo");
指定使用的插件。

```ts
// JSHooks
{
name?: string;
enforce?: "pre" | "post";
Expand All @@ -581,12 +580,15 @@ import(/* webpackIgnore: true */ "./foo");
}
```

JSHooks 是一组用来扩展 Mako 编译过程的钩子函数
你还可以在 hook 函数里用以下方法

- `name`,插件名称
- `buildStart`,构建开始前调用
- `load`,用于加载文件,返回文件内容和类型,类型支持 `css``js``jsx``ts``tsx`
- `generateEnd`,生成完成后调用,`isFirstCompile` 可用于判断是否为首次编译,`time` 为编译时间,`stats` 是编译统计信息
- `this.emitFile({ type: 'asset', fileName: string, source: string | Uint8Array })`, 添加文件到输出目录
- `this.warn(message: string)`, 添加一个警告
- `this.error(message: string)`, 添加一个错误
- `this.parse(code: string)`, 解析代码 (CURRENTLY NOT SUPPORTED)
- `this.addWatchFile(filePath: string)`, 添加一个监听文件 (CURRENTLY NOT SUPPORTED)

Plugins 兼容 [unplugin](https://unplugin.unjs.io/),所以你可以使用 unplugin 的插件,比如 [unplugin-icons](https://github.com/unplugin/unplugin-icons), [unplugin-replace](https://github.com/unplugin/unplugin-replace) 等。

### progress

Expand Down

0 comments on commit cb393de

Please sign in to comment.