generator-mico-cli 0.2.22 → 0.2.24

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.
Files changed (48) hide show
  1. package/README.md +33 -0
  2. package/bin/mico.js +15 -2
  3. package/generators/micro-react/index.js +44 -6
  4. package/generators/micro-react/meta.json +2 -1
  5. package/generators/micro-react/templates/CICD/start_dev.sh +12 -2
  6. package/generators/micro-react/templates/CICD/start_prod.sh +11 -1
  7. package/generators/micro-react/templates/CICD/start_test.sh +12 -1
  8. package/generators/micro-react/templates/_gitignore +3 -1
  9. package/generators/micro-react/templates/_npmrc +1 -0
  10. package/generators/micro-react/templates/apps/layout/config/config.prod.development.ts +16 -0
  11. package/generators/micro-react/templates/apps/layout/config/config.prod.testing.ts +16 -0
  12. package/generators/micro-react/templates/apps/layout/config/config.prod.ts +12 -0
  13. 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
  14. 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
  15. package/generators/micro-react/templates/apps/layout/mock/api.mock.ts +81 -61
  16. package/generators/micro-react/templates/apps/layout/mock/pages.ts +3 -3
  17. package/generators/micro-react/templates/apps/layout/src/app.tsx +5 -2
  18. package/generators/micro-react/templates/apps/layout/src/common/menu/parser.ts +7 -2
  19. package/generators/micro-react/templates/apps/layout/src/common/request/interceptors.ts +29 -1
  20. package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/index.less +1 -5
  21. package/generators/micro-react/templates/apps/layout/src/components/RightContent/AvatarDropdown.tsx +12 -16
  22. package/generators/micro-react/templates/apps/layout/src/layouts/components/menu/index.less +2 -1
  23. package/generators/micro-react/templates/apps/layout/src/layouts/components/menu/index.tsx +7 -8
  24. package/generators/micro-react/templates/apps/layout/src/services/user.ts +5 -1
  25. package/generators/micro-react/templates/package.json +2 -0
  26. package/generators/micro-react/templates/scripts/apply-sentry-plugin.ts +45 -0
  27. package/generators/micro-react/templates/scripts/collect-dist.js +10 -0
  28. package/generators/micro-react/templates/turbo.json +1 -1
  29. package/generators/subapp-react/index.js +46 -4
  30. package/generators/subapp-react/templates/homepage/config/config.dev.ts +0 -1
  31. package/generators/subapp-react/templates/homepage/config/config.prod.development.ts +9 -2
  32. package/generators/subapp-react/templates/homepage/config/config.prod.testing.ts +9 -2
  33. package/generators/subapp-react/templates/homepage/config/config.prod.ts +9 -2
  34. package/generators/subapp-react/templates/homepage/package.json +1 -0
  35. package/generators/subapp-react/templates/homepage/src/app.tsx +6 -0
  36. package/generators/subapp-umd/ignore-list.json +5 -0
  37. package/generators/subapp-umd/index.js +325 -0
  38. package/generators/subapp-umd/meta.json +11 -0
  39. package/generators/subapp-umd/templates/README.md +94 -0
  40. package/generators/subapp-umd/templates/package.json +35 -0
  41. package/generators/subapp-umd/templates/public/index.html +34 -0
  42. package/generators/subapp-umd/templates/src/App.less +15 -0
  43. package/generators/subapp-umd/templates/src/App.tsx +13 -0
  44. package/generators/subapp-umd/templates/src/index.ts +2 -0
  45. package/generators/subapp-umd/templates/tsconfig.json +27 -0
  46. package/generators/subapp-umd/templates/webpack.config.js +68 -0
  47. package/lib/utils.js +2 -1
  48. package/package.json +1 -1
@@ -0,0 +1,325 @@
1
+ 'use strict';
2
+
3
+ const Generator = require('yeoman-generator');
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const {
7
+ toKebab,
8
+ toPascal,
9
+ toCamel,
10
+ collectFiles,
11
+ transformDestPath,
12
+ isTemplateFile,
13
+ setupErrorHandlers,
14
+ createLogger,
15
+ loadMicorc,
16
+ } = require('../../lib/utils');
17
+
18
+ const IGNORE_LIST = require('./ignore-list.json');
19
+
20
+ setupErrorHandlers();
21
+
22
+ module.exports = class extends Generator {
23
+ initializing() {
24
+ this.monorepoRoot = process.cwd();
25
+ this.logger = createLogger(this);
26
+
27
+ this.isDryRun = this.options.dryRun || process.env.MICO_DRY_RUN === '1';
28
+
29
+ const { config: rcConfig, configPath } = loadMicorc(this.monorepoRoot);
30
+ this.rcConfig = rcConfig;
31
+ if (configPath) {
32
+ this.logger.verbose('Loaded config from:', configPath);
33
+ }
34
+
35
+ const packagesDir = path.join(this.monorepoRoot, 'packages');
36
+ const workspaceFile = path.join(this.monorepoRoot, 'pnpm-workspace.yaml');
37
+
38
+ if (!fs.existsSync(packagesDir)) {
39
+ console.error('');
40
+ console.error('❌ Error: packages directory not found.');
41
+ console.error('');
42
+ console.error(' This generator must be run from a monorepo root that contains a "packages" directory.');
43
+ console.error(` Current directory: ${this.monorepoRoot}`);
44
+ console.error('');
45
+ process.exit(1);
46
+ }
47
+
48
+ if (!fs.existsSync(workspaceFile)) {
49
+ console.warn('');
50
+ console.warn('⚠️ Warning: pnpm-workspace.yaml not found.');
51
+ console.warn(' Make sure you are in the correct monorepo.');
52
+ console.warn('');
53
+ }
54
+ }
55
+
56
+ _detectPackageScope() {
57
+ const rootPkgPath = path.join(this.monorepoRoot, 'package.json');
58
+ if (fs.existsSync(rootPkgPath)) {
59
+ try {
60
+ const pkg = JSON.parse(fs.readFileSync(rootPkgPath, 'utf-8'));
61
+ if (pkg.name) {
62
+ return pkg.name.startsWith('@')
63
+ ? pkg.name.replace(/^(@[^/]+)\/.*/, '$1')
64
+ : `@${pkg.name}`;
65
+ }
66
+ } catch (e) {
67
+ // ignore
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+
73
+ async prompting() {
74
+ try {
75
+ const detectedScope = this._detectPackageScope();
76
+ const rc = this.rcConfig || {};
77
+
78
+ this.answers = await this.prompt([
79
+ {
80
+ type: 'input',
81
+ name: 'appName',
82
+ message: 'Package name (e.g. my-widget)',
83
+ default: rc.defaultUmdName || 'my-widget',
84
+ filter: (input) => toKebab(input),
85
+ validate: (input) => {
86
+ const value = toKebab(input);
87
+ if (!value) return 'Package name is required';
88
+ const destDir = path.join(this.monorepoRoot, 'packages', value);
89
+ if (fs.existsSync(destDir)) {
90
+ return `Target already exists: packages/${value}`;
91
+ }
92
+ return true;
93
+ },
94
+ },
95
+ {
96
+ type: 'input',
97
+ name: 'umdGlobalName',
98
+ message: 'UMD global variable name (e.g. MyWidget)',
99
+ default: (answers) => toPascal(answers.appName),
100
+ validate: (input) => {
101
+ if (!input) return 'UMD global name is required';
102
+ if (!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(input)) {
103
+ return 'Must be a valid JavaScript identifier';
104
+ }
105
+ return true;
106
+ },
107
+ },
108
+ {
109
+ type: 'input',
110
+ name: 'packageScope',
111
+ message: 'Package scope',
112
+ default: rc.packageScope || detectedScope || '@my-project',
113
+ validate: (input) => {
114
+ if (!input) return 'Package scope is required';
115
+ if (!input.startsWith('@')) return 'Package scope must start with @';
116
+ return true;
117
+ },
118
+ },
119
+ {
120
+ type: 'input',
121
+ name: 'devPort',
122
+ message: 'Dev server port',
123
+ default: rc.umdDevPort || '9100',
124
+ validate: (input) => {
125
+ const port = Number(input);
126
+ if (!Number.isInteger(port) || port < 1024 || port > 65535) {
127
+ return 'Port must be an integer between 1024 and 65535';
128
+ }
129
+ return true;
130
+ },
131
+ },
132
+ ]);
133
+
134
+ this.appName = toKebab(this.answers.appName);
135
+ this.appNamePascal = toPascal(this.appName);
136
+ this.appNameCamel = toCamel(this.appName);
137
+ this.umdGlobalName = this.answers.umdGlobalName;
138
+ this.packageScope = this.answers.packageScope;
139
+ this.devPort = this.answers.devPort;
140
+ this.templateDir = this.templatePath();
141
+ this.destDir = path.join(this.monorepoRoot, 'packages', this.appName);
142
+ } catch (error) {
143
+ console.error('');
144
+ console.error('❌ Error during prompting:');
145
+ console.error(` ${error.message}`);
146
+ console.error('');
147
+ process.exit(1);
148
+ }
149
+ }
150
+
151
+ async writing() {
152
+ try {
153
+ if (!fs.existsSync(this.templateDir)) {
154
+ console.error('');
155
+ console.error('❌ Error: Template directory not found.');
156
+ console.error(` Expected: ${this.templateDir}`);
157
+ console.error('');
158
+ process.exit(1);
159
+ }
160
+
161
+ this.logger.verbose('Template directory:', this.templateDir);
162
+ this.logger.verbose('Destination directory:', this.destDir);
163
+
164
+ const templateData = {
165
+ appName: this.appName,
166
+ AppName: this.appNamePascal,
167
+ appNameCamel: this.appNameCamel,
168
+ umdGlobalName: this.umdGlobalName,
169
+ packageScope: this.packageScope,
170
+ devPort: this.devPort,
171
+ };
172
+
173
+ this.logger.verbose('Template data:', JSON.stringify(templateData, null, 2));
174
+
175
+ const files = collectFiles(this.templateDir, this.templateDir, IGNORE_LIST);
176
+
177
+ if (files.length === 0) {
178
+ console.error('');
179
+ console.error('❌ Error: No template files found.');
180
+ console.error(` Template directory: ${this.templateDir}`);
181
+ console.error('');
182
+ process.exit(1);
183
+ }
184
+
185
+ if (this.isDryRun) {
186
+ this.log('');
187
+ this.log('\x1b[33m📋 Dry run mode - no files will be created\x1b[0m');
188
+ this.log('');
189
+ this.log(` Package: ${this.appName}`);
190
+ this.log(` UMD global: ${this.umdGlobalName}`);
191
+ this.log(` Scope: ${this.packageScope}`);
192
+ this.log(` Dev port: ${this.devPort}`);
193
+ this.log(` Destination: packages/${this.appName}`);
194
+ this.log('');
195
+ this.log(' Would create the following files:');
196
+ this.log('');
197
+
198
+ let templateCount = 0;
199
+ let copyCount = 0;
200
+
201
+ for (const relPath of files) {
202
+ const destRelPath = transformDestPath(relPath);
203
+ const isTemplate = isTemplateFile(relPath);
204
+ const tag = isTemplate ? '\x1b[32m[tpl]\x1b[0m' : '\x1b[36m[cpy]\x1b[0m';
205
+ this.log(` ${tag} packages/${this.appName}/${destRelPath}`);
206
+
207
+ if (isTemplate) {
208
+ templateCount++;
209
+ } else {
210
+ copyCount++;
211
+ }
212
+ }
213
+
214
+ this.log('');
215
+ this.log(` Total: ${files.length} files (${templateCount} templates, ${copyCount} static)`);
216
+ this.log('');
217
+ this.log(' Run without --dry-run to actually create these files.');
218
+ this.log('');
219
+
220
+ this._skipInstall = true;
221
+ return;
222
+ }
223
+
224
+ this.log('');
225
+ this.log(`📦 Creating UMD package: ${this.appName}`);
226
+ this.log(` UMD global: ${this.umdGlobalName}`);
227
+ this.log(` Destination: packages/${this.appName}`);
228
+ this.log('');
229
+
230
+ let templateCount = 0;
231
+ let copyCount = 0;
232
+
233
+ for (const relPath of files) {
234
+ const srcPath = path.join(this.templateDir, relPath);
235
+ const destRelPath = transformDestPath(relPath);
236
+ const destPath = path.join(this.destDir, destRelPath);
237
+
238
+ if (isTemplateFile(relPath)) {
239
+ this.logger.file('template', destRelPath);
240
+ this.fs.copyTpl(srcPath, destPath, templateData);
241
+ templateCount++;
242
+ } else {
243
+ this.logger.file('copy', destRelPath);
244
+ this.fs.copy(srcPath, destPath);
245
+ copyCount++;
246
+ }
247
+ }
248
+
249
+ this.logger.verbose(`Processed: ${templateCount} templates, ${copyCount} copied`);
250
+ } catch (error) {
251
+ console.error('');
252
+ console.error('❌ Error during file generation:');
253
+ console.error(` ${error.message}`);
254
+ console.error('');
255
+ process.exit(1);
256
+ }
257
+ }
258
+
259
+ install() {
260
+ if (this._skipInstall) return;
261
+
262
+ this.log('');
263
+ this.log('📦 正在安装依赖...');
264
+ try {
265
+ this.spawnCommandSync('pnpm', ['install'], {
266
+ cwd: this.monorepoRoot,
267
+ });
268
+ } catch (e) {
269
+ this._installFailed = true;
270
+ this.log('');
271
+ this.log('⚠️ 依赖安装失败,但 UMD 包文件已全部生成。');
272
+ this.logger.verbose('Install error:', e.message);
273
+ return;
274
+ }
275
+
276
+ // 依赖安装成功后,格式化生成的文件
277
+ const prettierConfig = path.join(this.monorepoRoot, 'apps/layout/.prettierrc');
278
+ if (fs.existsSync(prettierConfig)) {
279
+ try {
280
+ this.spawnCommandSync(
281
+ 'pnpm',
282
+ [
283
+ '-C', 'apps/layout', 'exec', 'prettier',
284
+ '--config', prettierConfig,
285
+ '--write',
286
+ `${this.destDir}/**/*.{ts,tsx,js,jsx,json,less,md}`,
287
+ ],
288
+ { cwd: this.monorepoRoot },
289
+ );
290
+ } catch (e) {
291
+ this.logger.verbose('Formatting failed (non-critical):', e.message);
292
+ }
293
+ }
294
+ }
295
+
296
+ end() {
297
+ if (this._skipInstall) return;
298
+
299
+ this.log('');
300
+
301
+ if (this._installFailed) {
302
+ this.log('⚠️ UMD 包文件已创建,但依赖安装未完成。');
303
+ this.log('');
304
+ this.log(' 请手动安装依赖:');
305
+ this.log('');
306
+ this.log(' pnpm install');
307
+ this.log('');
308
+ this.log(' 如果安装仍然失败,可尝试:');
309
+ this.log(' pnpm install --network-concurrency 4');
310
+ } else {
311
+ this.log('✅ UMD 包创建成功!');
312
+ }
313
+
314
+ this.log('');
315
+ this.log(' 后续步骤:');
316
+ this.log('');
317
+ this.log(` cd packages/${this.appName}`);
318
+ this.log(' pnpm dev');
319
+ this.log('');
320
+ this.log(' 开发模式:');
321
+ this.log(` • 预览页面: http://localhost:${this.devPort}/`);
322
+ this.log(` • UMD 文件: http://localhost:${this.devPort}/${this.appName}.umd.js`);
323
+ this.log('');
324
+ }
325
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "subapp-umd",
3
+ "description": "在现有 Monorepo 中创建 UMD 组件包(Webpack 构建)",
4
+ "usage": "cd <monorepo-root> && mico create subapp-umd",
5
+ "features": [
6
+ "Webpack UMD 构建",
7
+ "React 18 + TypeScript",
8
+ "dev server 同时提供 HTML 预览和 UMD JS",
9
+ "Source Map 源码调试"
10
+ ]
11
+ }
@@ -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,15 @@
1
+ .<%= appName %>-container {
2
+ padding: 16px;
3
+
4
+ h2 {
5
+ margin: 0 0 8px;
6
+ font-size: 20px;
7
+ color: #1d2129;
8
+ }
9
+
10
+ p {
11
+ margin: 0;
12
+ color: #86909c;
13
+ font-size: 14px;
14
+ }
15
+ }
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import './App.less';
3
+
4
+ const App: React.FC = () => {
5
+ return (
6
+ <div className="<%= appName %>-container">
7
+ <h2><%= AppName %></h2>
8
+ <p>UMD component is working.</p>
9
+ </div>
10
+ );
11
+ };
12
+
13
+ export default App;
@@ -0,0 +1,2 @@
1
+ export { default } from './App';
2
+ export { default as App } from './App';
@@ -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
@@ -109,7 +109,8 @@ const TEMPLATE_EXTENSIONS = new Set([
109
109
  '.less',
110
110
  '.md',
111
111
  '.mdc',
112
- '.sh'
112
+ '.sh',
113
+ '.html'
113
114
  ]);
114
115
 
115
116
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-mico-cli",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
4
4
  "description": "Yeoman generator for Mico CLI projects",
5
5
  "keywords": ["yeoman-generator", "generator", "cli"],
6
6
  "license": "MIT",