@micro-app/core
Version:
[Core] Pluggable micro application framework.
207 lines (156 loc) • 4.68 kB
Markdown
Pluggable micro application framework.
基于webpack多入口的多仓库业务模块开发的插件应用框架核心库.
[![Github Actions Coveralls][Github-Actions-Coveralls]][Github-Actions-Coveralls-url]
[![Coverage Status][Coverage-img]][Coverage-url]
[![NPM Version][npm-img]][npm-url]
[![NPM Download][download-img]][download-url]
[]: https://github.com/MicroAppJS/core/workflows/Coveralls/badge.svg
[]: https://github.com/MicroAppJS/core
[]: https://coveralls.io/repos/github/MicroAppJS/core/badge.svg?branch=master
[]: https://coveralls.io/github/MicroAppJS/core?branch=master
[]: https://img.shields.io/npm/v/@micro-app/core.svg?style=flat-square
[]: https://npmjs.org/package/@micro-app/core
[]: https://img.shields.io/npm/dm/@micro-app/core.svg?style=flat-square
[]: https://npmjs.org/package/@micro-app/core
```sh
yarn add @micro-app/core
```
or
```sh
npm install -D @micro-app/core
```
```sh
npx micro-app init
```
```js
module.exports = {
name: '@micro-app/demo',
description: '',
version: '0.0.1',
type: '', // type 类型
staticPath: '', // String | Array
entry: { // 入口
main: './test/index.js',
},
// htmls: [ // 输出模版配置
// {
// template: './test/index.js',
// },
// ],
alias: { // 别名配置
api: '',
config: {
link: '',
description: '配置',
},
service: {
link: '',
description: '接口',
type: 'server',
},
},
strict: true, // 严格强依赖模式
micros: [ 'test' ], // 被注册的容器
plugins: [ // 自定义插件
// [{
// id: 'test',
// description: '这是test',
// link: __dirname + '/test/testPlugin',
// }, {
// a: 1,
// }],
],
};
```
```json
"dependencies": {
"@micro-app/test": "git+ssh://git@github.com/micro-app.git#test"
},
```
```js
const api = require('@micro-demo/api');
```
```js
plugins: [
[ // 1
{
id: 'test', // 插件 id
description: '这是test', // 插件描述
link: __dirname + '/test/testPlugin.js', // 插件地址
}, { // 注册入的 opts
a: 1,
}
],
],
```
文件必须返回一个方法.
```js
module.exports = function(api, opts) {
console.log(opts);
api.onInitDone(item => {
console.log('init Done', item);
});
api.onInitDone(() => {
console.log('init Done2', api.getState('webpackConfig'));
});
api.onPluginInitDone(item => {
console.log('onPluginInitDone', item);
});
};
```
可通过如下命令进行动态查看
```js
npx micro-app show methods
```
以提供的方法如下, `System Build-in` 为内置方法
```js
╰─➤ npx micro-app show methods
Plugin Methods:
* onPluginInitDone ( System Build-in )
* beforeMergeConfig ( System Build-in )
* afterMergeConfig ( System Build-in )
* onInitWillDone ( System Build-in )
* onInitDone ( System Build-in )
* modifyCommand ( System Build-in )
* onRunCommand ( System Build-in )
* modifyCommandHelp ( System Build-in )
```
```js
╰─➤ npx micro-app help
Usage: micro-app <command> [options]
Commands:
* show ( show alias & shared list, etc. )
* check ( check all dependencies. )
* version ( show version )
* start ( runs server for production )
* serve ( runs server for development )
* build ( build for production )
* update ( update package.json )
* deploy ( sync commit status. )
run micro-app help [command] for usage of a specific command.
```
```js
npx micro-app show micros
```
```js
npx micro-app show alias
```
```js
npx micro-app show shared
```