From cb393dee725364a69816f19fbb23f3eed6bef938 Mon Sep 17 00:00:00 2001 From: sorrycc Date: Tue, 24 Dec 2024 17:05:27 +0800 Subject: [PATCH] docs: improve --- docs/config.md | 14 ++++++++------ docs/config.zh-CN.md | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/docs/config.md b/docs/config.md index 06099781a..76bae5ed6 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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"; @@ -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 diff --git a/docs/config.zh-CN.md b/docs/config.zh-CN.md index a32f5ed1c..2a6b15286 100644 --- a/docs/config.zh-CN.md +++ b/docs/config.zh-CN.md @@ -556,7 +556,6 @@ import(/* webpackIgnore: true */ "./foo"); 指定使用的插件。 ```ts -// JSHooks { name?: string; enforce?: "pre" | "post"; @@ -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