Skip to content

Commit

Permalink
docs: supplyment plugin api documentation (#11957)
Browse files Browse the repository at this point in the history
* docs: supplyment plugin api documentation

* docs: supplyment plugin api documentation

* docs: supplyment plugin api documentation

* docs: supplyment plugin api documentation

* docs: simple example

---------

Co-authored-by: fz6m <59400654+fz6m@users.noreply.github.com>
  • Loading branch information
MissNanLan and fz6m authored Dec 21, 2023
1 parent 4ced230 commit 57f2357
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/docs/docs/api/plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,53 @@ api.registerPlugins([

### registerGenerator

注册微生成器用来快捷生成模板代码。

示例:

```ts
import { GeneratorType } from '@umijs/core';
import { logger } from '@umijs/utils';
import { join } from 'path';
import { writeFileSync } from 'fs';

api.registerGenerator({
key: 'editorconfig',
name: 'Create .editorconfig',
description: 'Setup editorconfig config',
type: GeneratorType.generate,
fn: () => {
const configFilePath = join(api.cwd, '.editorconfig')
if (existsSync(configFilePath)) {
logger.info(`The .editorconfig file already exists.`)
return
}
writeFileSync(
configFilePath,
`
# 🎨 http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
`.trimStart(),
'utf-8'
)
logger.info(`Generate .editorconfig file successful.`)
}
})
```

更多示例见 [`已有生成器源码`](https://github.com/umijs/umi/tree/master/packages/preset-umi/src/commands/generators)

### skipPlugins
```ts
api.skipPlugins( keys: string[])
Expand Down

1 comment on commit 57f2357

@vercel
Copy link

@vercel vercel bot commented on 57f2357 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.