-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve plugin system #710
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pull Request Test Coverage Report for Build 844
💛 - Coveralls |
|
export default class extends Plugin {
start() {
}
addMiddleware() {
return [ middleware1 ];
}
addHTML() {
return {
head: `<title>${this.config.title}</title>`,
body: '',
};
}
addAlias() {
return {
}
}
addCustomConfig() {
return [{
name: 'title',
beforePos: "addHTML" // choose the pos
}]
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TODO
例子
在入口文件 .umi/umi.js 添加一行
alert('hello umi plugin!');
。说明
umi 整体是由插件串联起来的,除了基础功能,umi 内部也是由插件实现的。
插件可以做什么?
注册命令行
umi 内部的 dev、build、test 都是由此实现,bigfish 的 pack 也可以改成这种方式。
参考:https://github.com/umijs/umi/blob/master/packages/umi-build-dev/src/plugins/commands/dev/index.js#L25
挖坑填坑
插件本质上就是挖坑和填坑,umi 里的坑(hooks)分两类:
on
,before
和after
为前缀modify
为前缀,提供 memo 供修改事件类型。
修改类型。
注意点:
UI 插件
https://cli.vuejs.org/dev-guide/ui-api.html#project-configurations
方案待定。
比如,我们有整体的 UI 配置界面,然后可以在这里添加额外的 UI 配置项:
插件接口
环境变量
api 方法
封装 register 的辅助方法:
api.service
umi-utils
Hooks
生命周期相关
临时文件生成相关
路由相关
HTML 相关
配置相关
webpackDevServer 相关