generator-mico-cli 0.2.22 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/bin/mico.js +15 -2
- package/generators/micro-react/index.js +44 -6
- package/generators/micro-react/meta.json +2 -1
- package/generators/micro-react/templates/_gitignore +3 -1
- package/generators/micro-react/templates/_npmrc +1 -0
- package/generators/micro-react/templates/apps/layout/config/config.prod.development.ts +5 -0
- package/generators/micro-react/templates/apps/layout/config/config.prod.testing.ts +5 -0
- package/generators/micro-react/templates/apps/layout/config/config.prod.ts +12 -0
- package/generators/micro-react/templates/apps/layout/docs/feature-/345/276/256/345/211/215/347/253/257/346/250/241/345/274/217.md +0 -1
- package/generators/micro-react/templates/apps/layout/docs/feature-/350/217/234/345/215/225/346/235/203/351/231/220/346/216/247/345/210/266.md +9 -8
- package/generators/micro-react/templates/apps/layout/mock/api.mock.ts +81 -61
- package/generators/micro-react/templates/apps/layout/mock/pages.ts +3 -3
- package/generators/micro-react/templates/apps/layout/package.json +1 -0
- package/generators/micro-react/templates/apps/layout/src/app.tsx +5 -2
- package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/index.less +1 -5
- package/generators/micro-react/templates/apps/layout/src/components/RightContent/AvatarDropdown.tsx +12 -16
- package/generators/micro-react/templates/apps/layout/src/layouts/components/menu/index.less +2 -1
- package/generators/micro-react/templates/apps/layout/src/layouts/components/menu/index.tsx +7 -8
- package/generators/micro-react/templates/apps/layout/src/services/user.ts +5 -1
- package/generators/micro-react/templates/package.json +1 -0
- package/generators/micro-react/templates/scripts/apply-sentry-plugin.ts +45 -0
- package/generators/subapp-react/index.js +46 -4
- package/generators/subapp-react/templates/homepage/config/config.dev.ts +0 -1
- package/generators/subapp-react/templates/homepage/config/config.prod.development.ts +2 -2
- package/generators/subapp-react/templates/homepage/config/config.prod.testing.ts +2 -2
- package/generators/subapp-react/templates/homepage/config/config.prod.ts +9 -2
- package/generators/subapp-react/templates/homepage/package.json +1 -0
- package/generators/subapp-react/templates/homepage/src/app.tsx +6 -0
- package/generators/subapp-umd/ignore-list.json +5 -0
- package/generators/subapp-umd/index.js +325 -0
- package/generators/subapp-umd/meta.json +11 -0
- package/generators/subapp-umd/templates/README.md +94 -0
- package/generators/subapp-umd/templates/package.json +35 -0
- package/generators/subapp-umd/templates/public/index.html +34 -0
- package/generators/subapp-umd/templates/src/App.less +15 -0
- package/generators/subapp-umd/templates/src/App.tsx +13 -0
- package/generators/subapp-umd/templates/src/index.ts +2 -0
- package/generators/subapp-umd/templates/tsconfig.json +27 -0
- package/generators/subapp-umd/templates/webpack.config.js +68 -0
- package/lib/utils.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# <%= AppName %>
|
|
2
|
+
|
|
3
|
+
UMD 组件包,基于 Webpack 构建,支持通过 `<script>` 标签加载。
|
|
4
|
+
|
|
5
|
+
## 快速开始
|
|
6
|
+
|
|
7
|
+
### 安装依赖
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# 在项目根目录执行
|
|
11
|
+
pnpm install
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### 本地开发
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm dev
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
启动后可通过两种方式使用:
|
|
21
|
+
|
|
22
|
+
| URL | 用途 |
|
|
23
|
+
|---|---|
|
|
24
|
+
| `http://localhost:<%= devPort %>/` | HTML 预览页,独立调试组件 |
|
|
25
|
+
| `http://localhost:<%= devPort %>/<%= appName %>.umd.js` | UMD JS 文件,供主应用联调 |
|
|
26
|
+
|
|
27
|
+
DevTools Sources 面板中可在 `webpack://<%= appName %>/src/` 下定位原始 TypeScript 源码进行断点调试。
|
|
28
|
+
|
|
29
|
+
### 构建
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm build
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
产物输出到 `dist/` 目录:
|
|
36
|
+
- `dist/<%= appName %>.umd.js` — UMD bundle
|
|
37
|
+
- `dist/<%= appName %>.css` — 样式文件(如有)
|
|
38
|
+
|
|
39
|
+
### 在浏览器中使用
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<!-- 1. 加载 React(宿主环境提供) -->
|
|
43
|
+
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
|
44
|
+
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
|
45
|
+
|
|
46
|
+
<!-- 2. 加载 UMD 组件 -->
|
|
47
|
+
<link rel="stylesheet" href="path/to/<%= appName %>.css" />
|
|
48
|
+
<script src="path/to/<%= appName %>.umd.js"></script>
|
|
49
|
+
|
|
50
|
+
<!-- 3. 使用 -->
|
|
51
|
+
<script>
|
|
52
|
+
var App = window['<%= umdGlobalName %>'].default;
|
|
53
|
+
var root = ReactDOM.createRoot(document.getElementById('root'));
|
|
54
|
+
root.render(React.createElement(App));
|
|
55
|
+
</script>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 主应用联调
|
|
59
|
+
|
|
60
|
+
在主应用的 mock 菜单中配置 `jsUrls` 指向本地 dev server:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"jsUrls": ["//localhost:<%= devPort %>/<%= appName %>.umd.js"]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 目录结构
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
<%= appName %>/
|
|
72
|
+
├── public/
|
|
73
|
+
│ └── index.html # 本地开发预览页
|
|
74
|
+
├── src/
|
|
75
|
+
│ ├── index.ts # UMD 入口
|
|
76
|
+
│ ├── App.tsx # 主组件
|
|
77
|
+
│ └── App.less # 样式
|
|
78
|
+
├── webpack.config.js # Webpack 配置
|
|
79
|
+
├── tsconfig.json # TypeScript 配置
|
|
80
|
+
└── package.json
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 全局变量
|
|
84
|
+
|
|
85
|
+
UMD 包加载后,可通过 `window.<%= umdGlobalName %>` 访问导出内容。
|
|
86
|
+
|
|
87
|
+
## External 依赖
|
|
88
|
+
|
|
89
|
+
以下依赖不打入包体,需由宿主环境提供:
|
|
90
|
+
|
|
91
|
+
| 包名 | 全局变量 |
|
|
92
|
+
|---|---|
|
|
93
|
+
| `react` | `React` |
|
|
94
|
+
| `react-dom` | `ReactDOM` |
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= packageScope %>/<%= appName %>",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "UMD package - <%= appName %>",
|
|
5
|
+
"main": "./dist/<%= appName %>.umd.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "webpack serve --mode development",
|
|
11
|
+
"build": "webpack --mode production",
|
|
12
|
+
"build:development": "webpack --mode development",
|
|
13
|
+
"clean": "rm -rf dist"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": "^18.0.0",
|
|
17
|
+
"react-dom": "^18.0.0",
|
|
18
|
+
"@mico-platform/ui": ">=0.0.13"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/react": "^18.3.26",
|
|
22
|
+
"@types/react-dom": "^18.3.7",
|
|
23
|
+
"css-loader": "^7.1.2",
|
|
24
|
+
"style-loader": "^4.0.0",
|
|
25
|
+
"html-webpack-plugin": "^5.6.3",
|
|
26
|
+
"less": "^4.3.0",
|
|
27
|
+
"less-loader": "^12.2.0",
|
|
28
|
+
"mini-css-extract-plugin": "^2.9.2",
|
|
29
|
+
"ts-loader": "^9.5.2",
|
|
30
|
+
"typescript": "^5.8.3",
|
|
31
|
+
"webpack": "^5.99.9",
|
|
32
|
+
"webpack-cli": "^6.0.1",
|
|
33
|
+
"webpack-dev-server": "^5.2.1"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title><%= AppName %> - UMD Dev Preview</title>
|
|
7
|
+
<style>
|
|
8
|
+
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
|
|
9
|
+
#root { padding: 24px; }
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<div id="root"></div>
|
|
14
|
+
|
|
15
|
+
<!-- React (external, provided by host environment) -->
|
|
16
|
+
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
|
|
17
|
+
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
|
|
18
|
+
|
|
19
|
+
<!-- UMD Bundle -->
|
|
20
|
+
<script src="/<%= appName %>.umd.js"></script>
|
|
21
|
+
|
|
22
|
+
<script>
|
|
23
|
+
var mod = window['<%= umdGlobalName %>'];
|
|
24
|
+
var App = mod && (mod.default || mod.App || mod);
|
|
25
|
+
if (App) {
|
|
26
|
+
var root = ReactDOM.createRoot(document.getElementById('root'));
|
|
27
|
+
root.render(React.createElement(App));
|
|
28
|
+
} else {
|
|
29
|
+
document.getElementById('root').innerHTML =
|
|
30
|
+
'<p style="color:red">Error: window.<%= umdGlobalName %> not found. Check UMD global name.</p>';
|
|
31
|
+
}
|
|
32
|
+
</script>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"noUnusedLocals": false,
|
|
14
|
+
"noUnusedParameters": false,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"declarationMap": true,
|
|
18
|
+
"declarationDir": "./dist",
|
|
19
|
+
"outDir": "./dist",
|
|
20
|
+
"baseUrl": ".",
|
|
21
|
+
"paths": {
|
|
22
|
+
"@/*": ["src/*"]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"include": ["src/**/*"],
|
|
26
|
+
"exclude": ["node_modules", "dist"]
|
|
27
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
3
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
4
|
+
|
|
5
|
+
module.exports = (env, argv) => {
|
|
6
|
+
const isProd = argv.mode === 'production';
|
|
7
|
+
const outputFilename = '<%= appName %>.umd.js';
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
entry: './src/index.ts',
|
|
11
|
+
output: {
|
|
12
|
+
path: path.resolve(__dirname, 'dist'),
|
|
13
|
+
filename: outputFilename,
|
|
14
|
+
publicPath: '/',
|
|
15
|
+
library: '<%= umdGlobalName %>',
|
|
16
|
+
libraryTarget: 'umd',
|
|
17
|
+
umdNamedDefine: true,
|
|
18
|
+
globalObject: 'typeof self !== "undefined" ? self : this',
|
|
19
|
+
clean: true,
|
|
20
|
+
},
|
|
21
|
+
externals: {
|
|
22
|
+
react: 'React',
|
|
23
|
+
'react-dom': 'ReactDOM',
|
|
24
|
+
'@mico-platform/ui': 'micoUI',
|
|
25
|
+
},
|
|
26
|
+
resolve: {
|
|
27
|
+
extensions: ['.ts', '.tsx', '.js', '.jsx'],
|
|
28
|
+
},
|
|
29
|
+
module: {
|
|
30
|
+
rules: [
|
|
31
|
+
{
|
|
32
|
+
test: /\.tsx?$/,
|
|
33
|
+
use: 'ts-loader',
|
|
34
|
+
exclude: /node_modules/,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
test: /\.less$/,
|
|
38
|
+
use: ['style-loader', 'css-loader', 'less-loader'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
test: /\.css$/,
|
|
42
|
+
use: ['style-loader', 'css-loader'],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
plugins: [
|
|
47
|
+
new HtmlWebpackPlugin({
|
|
48
|
+
template: './public/index.html',
|
|
49
|
+
inject: false,
|
|
50
|
+
}),
|
|
51
|
+
...(isProd
|
|
52
|
+
? [new MiniCssExtractPlugin({ filename: '<%= appName %>.css' })]
|
|
53
|
+
: []),
|
|
54
|
+
],
|
|
55
|
+
devtool: isProd ? false : 'source-map',
|
|
56
|
+
devServer: {
|
|
57
|
+
port: <%= devPort %>,
|
|
58
|
+
hot: true,
|
|
59
|
+
open: false,
|
|
60
|
+
headers: {
|
|
61
|
+
'Access-Control-Allow-Origin': '*',
|
|
62
|
+
},
|
|
63
|
+
static: {
|
|
64
|
+
directory: path.join(__dirname, 'public'),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
};
|
package/lib/utils.js
CHANGED