1- # Micro APP
1+ # Micro APP CLI
2+
3+ Pluggable application framework.
4+
5+ [ ![ NPM Version] [ npm-img ]] [ npm-url ]
6+ [ ![ NPM Download] [ download-img ]] [ download-url ]
7+
8+ [ npm-img ] : https://img.shields.io/npm/v/@micro-app/cli.svg?style=flat-square
9+ [ npm-url ] : https://npmjs.org/package/@micro-app/cli
10+ [ download-img ] : https://img.shields.io/npm/dm/@micro-app/cli.svg?style=flat-square
11+ [ download-url ] : https://npmjs.org/package/@micro-app/cli
212
313## Install
414
@@ -35,11 +45,13 @@ module.exports = {
3545 // },
3646 },
3747
38- entry: {
48+ staticPath: [], // String | Array
49+
50+ entry: { // 入口
3951 main: ' ./test/index.js' ,
4052 },
4153
42- htmls: [
54+ htmls: [ // 输出模版配置
4355 {
4456 template: ' ./test/index.js' ,
4557 },
@@ -51,7 +63,7 @@ module.exports = {
5163 // },
5264 // ],
5365
54- alias: { // 前端
66+ alias: { // 别名配置
5567 api: ' ' ,
5668 config: {
5769 link: ' ' ,
@@ -64,7 +76,7 @@ module.exports = {
6476 },
6577 },
6678
67- strict: true ,
79+ strict: true , // 严格强依赖模式
6880
6981 micros: [ ' test' ], // 被注册的容器
7082 // micros$$test: { // 单独配置
@@ -82,7 +94,7 @@ module.exports = {
8294 },
8395 },
8496
85- plugins: [
97+ plugins: [ // 自定义插件
8698 // [{
8799 // id: 'test',
88100 // description: '这是test',
@@ -156,22 +168,191 @@ const api = require('@micro-demo/api');
156168
157169## Plugins 扩展
158170
171+ ### 首先在 micro-app.config.js 中注册插件
172+
173+ ``` js
174+ plugins: [
175+ [ // 1
176+ {
177+ id: ' test' , // 插件 id
178+ description: ' 这是test' , // 插件描述
179+ link: __dirname + ' /test/testPlugin.js' , // 插件地址
180+ }, { // 注册入的 opts
181+ a: 1 ,
182+ }
183+ ],
184+ ],
185+ ```
186+
187+ ### 插件文件 ` testPlugin.js `
188+
189+ 文件必须返回一个方法.
190+
191+ ``` js
192+ module .exports = function (api , opts ) {
193+ console .log (opts);
194+ api .onInitDone (item => {
195+ console .log (' init Done' , item);
196+ });
197+ api .onInitDone (() => {
198+ console .log (' init Done2' , api .getState (' webpackConfig' ));
199+ });
200+ api .onPluginInitDone (item => {
201+ console .log (' onPluginInitDone' , item);
202+ });
203+ api .beforeMergeWebpackConfig (item => {
204+ console .log (' beforeMergeWebpackConfig' , item);
205+ });
206+ api .afterMergeWebpackConfig (item => {
207+ console .log (' afterMergeWebpackConfig' , item);
208+ });
209+ // api.onChainWebpcakConfig(webpackChainConfig => {
210+ // console.log('onChainWebpcakConfig', webpackChainConfig);
211+ // });
212+ };
213+ ```
214+
215+ ### 内置部分插件提供的 api 方法
216+
217+ 可通过如下命令进行动态查看
218+
219+ ``` js
220+ npx micro- app show methods
221+ ```
222+
223+ 以提供的方法如下, ` System Build-in ` 为内置方法
224+
225+ ``` js
226+ ╰─➤ npx micro- app show methods
227+ Plugin Methods:
228+ * onPluginInitDone ( System Build- in )
229+ * beforeMergeConfig ( System Build- in )
230+ * afterMergeConfig ( System Build- in )
231+ * beforeMergeServerConfig ( System Build- in )
232+ * afterMergeServerConfig ( System Build- in )
233+ * onInitWillDone ( System Build- in )
234+ * onInitDone ( System Build- in )
235+ * modifyCommand ( System Build- in )
236+ * onRunCommand ( System Build- in )
237+ * modifyCommandHelp ( System Build- in )
238+ * beforeMergeWebpackConfig ( 合并 webpack 配置之前事件 )
239+ * afterMergeWebpackConfig ( 合并 webpack 配置之后事件 )
240+ * modifyChainWebpcakConfig ( 合并之后提供 webpack- chain 进行再次修改事件 )
241+ * onChainWebpcakConfig ( 修改之后提供 webpack- chain 进行查看事件 )
242+ * onServerInit ( 服务初始化时事件 )
243+ * onServerInitDone ( 服务初始化完成事件 )
244+ * onServerRunSuccess ( 服务运行启动成功时事件 )
245+ * onServerRunFail ( 服务运行启动失败时事件 )
246+ * beforeServerEntry ( 服务进入业务逻辑前事件 )
247+ * afterServerEntry ( 服务从业务逻辑出来后事件 )
248+ * modifyWebpackCompiler ( 对服务启动前对 webpack compiler 进行修改, 需要返回所有参数 )
249+ * beforeDevServer ( 开发服务创建前事件 )
250+ * afterDevServer ( 开发服务创建后事件 )
251+ * onBuildSuccess ( 构建成功时事件 )
252+ * onBuildFail ( 构建失败时事件 )
253+ * beforeBuild ( 开始构建前事件 )
254+ * afterBuild ( 构建结束后事件 )
255+ * beforeCommandUpdate ( 开始更新前事件 )
256+ * afterCommandUpdate ( 更新完毕后事件 )
257+ * beforeCommandDeploy ( 发布前事件 )
258+ * afterCommandDeploy ( 发布后事件 )
259+ * modifyCommandDeployMessage ( 发布消息二次编辑事件 )
260+
261+ // 以下为针对 vusion 类型的方法
262+ * modifyVusionConfig ( 对服务启动前对 vusion config 进行修改, 需要返回所有参数 )
263+ * modifyVusionWebpackConfig ( 对服务启动前对 vusion webpackConfig 进行修改, 需要返回所有参数 )
264+ * modifyDefaultVusionConfig ( 初始化修改通用 vusion .config .js , 需要返回所有参数 )
265+ ```
266+
267+ ### api 方法扩展
268+
269+ 可参考以下插件, 如:
270+
271+ ``` js
272+ // 注册一个方法
273+ api .registerMethod (' beforeCommandUpdate' , {
274+ type: api .API_TYPE .EVENT ,
275+ description: ' 开始更新前事件' ,
276+ });
277+
278+ // 注册一个终端命令
279+ api .registerCommand (' update' , {
280+ description: ' update package.json' ,
281+ usage: ' micro-app update [options]' ,
282+ options: {
283+ ' -' : ' update all.' ,
284+ ' -n <name>' : ' only update <name>.' ,
285+ },
286+ details: `
287+ Examples:
288+ ${ chalk .gray (' # update all' )}
289+ micro-app update
290+ ${ chalk .gray (' # only update <name>' )}
291+ micro-app update -n <name>
292+ ` .trim (),
293+ }, args => {
294+ const name = args .n ;
295+ return updateMicro (api, name);
296+ });
297+
298+ // 对外抛出已注册的方法.
299+ api .applyPluginHooks (' beforeCommandUpdate' , { name, logger, microsConfig });
300+
301+ ```
302+
303+ 其它插件使用 ` beforeCommandUpdate ` 方法, 如下:
304+
305+ ``` js
306+ api .beforeCommandUpdate (item => {
307+ console .log (' beforeCommandUpdate' , item);
308+ });
309+ ```
310+
159311## 其他
160312
161- - 展示所有容器
313+ ### 已支持的终端命令行
314+
315+ ``` js
316+ ╰─➤ npx micro- app help
317+
318+
319+ Usage: micro- app < command> [options]
320+
321+
322+ Commands:
323+ * show ( show alias & shared list, etc. )
324+ * check ( check all dependencies. )
325+ * version ( show version )
326+ * start ( runs server for production )
327+ * serve ( runs server for development )
328+ * build ( build for production )
329+ * update ( update package .json )
330+ * deploy ( sync commit status. )
331+
332+
333+ run micro- app help [command] for usage of a specific command.
334+ ```
335+
336+ ### 展示所有容器
162337
163338``` js
164339npx micro- app show micros
165340```
166341
167- - 展示所有前端共享接口
342+ ### 展示所有前端共享接口
168343
169344``` js
170345npx micro- app show alias
171346```
172347
173- - 展示所有后端共享接口
348+ ### 展示所有全局共享接口
174349
175350``` js
176351npx micro- app show shared
177352```
353+
354+ ### 启动开发模式
355+
356+ ``` js
357+ npx micro- app- dev -- progress
358+ ```
0 commit comments