@yannick-z/modulo 0.2.0 → 0.3.1
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/.vscode/extensions.json +3 -0
- package/README.md +57 -60
- package/bin/modulo.js +29 -19
- package/biome.json +34 -0
- package/package.json +36 -35
- package/rslib.config.ts +19 -19
- package/src/args/get-framework-name.ts +7 -7
- package/src/args/index.ts +16 -74
- package/src/args/preset.ts +16 -16
- package/src/cli/init.ts +10 -6
- package/src/cli/pack-code.ts +20 -9
- package/src/config/example/example-config.ts +50 -39
- package/src/config/example/example-externals.ts +21 -37
- package/src/config/index.ts +186 -16
- package/src/config/presets.ts +100 -0
- package/src/config/type.ts +34 -12
- package/src/index.ts +104 -10
- package/src/initiator/create-config-file.ts +52 -36
- package/src/initiator/create-project.ts +249 -0
- package/src/initiator/modify-scripts.ts +42 -42
- package/src/packer/auto-external-plugin.ts +205 -0
- package/src/packer/collect-modules.ts +58 -69
- package/src/packer/get-externals-and-tags.ts +82 -55
- package/src/packer/lib.ts +78 -70
- package/src/packer/page.ts +105 -82
- package/src/packer/prepare.ts +63 -57
- package/src/tools/cli.ts +21 -0
- package/src/tools/file.ts +84 -14
- package/src/tools/find-path-root.ts +52 -25
- package/src/tools/get-framework-name.ts +7 -7
- package/src/tools/get-ui-plugin.ts +27 -13
- package/src/tools/json.ts +63 -9
- package/src/tools/log.ts +58 -0
- package/src/tools/merge-user-config.ts +17 -17
- package/src/tools/omit-root-path.ts +17 -7
- package/src/tools/panic.ts +12 -8
- package/src/tools/string.ts +13 -2
- package/src/type/guard.ts +22 -3
- package/tsconfig.json +9 -9
- package/dist/index.js +0 -773
- package/src/args/cmd.ts +0 -16
- package/src/args/mode.ts +0 -38
- package/src/args/node_env.ts +0 -15
- package/src/args/target.ts +0 -44
- package/src/config/externals.ts +0 -70
- package/src/config/generate_config.ts +0 -105
- package/src/config/preset/alias.ts +0 -3
- package/src/config/preset/dev-server.ts +0 -6
- package/src/config/preset/dirs.ts +0 -12
- package/src/config/preset/html.ts +0 -19
- package/src/config/preset/index.ts +0 -23
- package/src/config/preset/libs.ts +0 -5
- package/src/config/preset/minify.ts +0 -24
- package/src/config/preset/url.ts +0 -4
- package/src/tools/debug-log.ts +0 -37
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Modulo - 高性能通用前端打包工具
|
|
2
2
|
|
|
3
|
-
Modulo 是一款现代、灵活且功能强大的通用前端项目打包工具。它基于高性能的 Rust
|
|
3
|
+
Modulo 是一款现代、灵活且功能强大的通用前端项目打包工具。它基于高性能的 Rust 工具链 (Rspack/Rsbuild),旨在为现代前端项目提供极速的开发体验和高效的构建流程。通过简洁的配置,Modulo 即可支持 React、Vue 等多种主流框架,并具备良好的扩展性。
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -10,29 +10,30 @@ Modulo 是一款现代、灵活且功能强大的通用前端项目打包工具
|
|
|
10
10
|
- [📦 先决条件](#-先决条件)
|
|
11
11
|
- [🚀 命令行接口 (CLI)](#-命令行接口-cli)
|
|
12
12
|
- [🧠 核心概念:入口发现机制](#-核心概念入口发现机制)
|
|
13
|
-
- [⚙️ 配置文件 (`modulo.config.
|
|
13
|
+
- [⚙️ 配置文件 (`modulo.config.ts`)](#️-配置文件-moduloconfigts)
|
|
14
14
|
- [🌐 强大的 `externals` 配置](#-强大的-externals-配置)
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
## ✨ 核心功能
|
|
19
19
|
|
|
20
|
-
- **极速构建**: 底层采用高性能 Rust
|
|
20
|
+
- **极速构建**: 底层采用高性能 Rust 工具链 (Rspack/Rsbuild),提供极致的开发和构建速度。
|
|
21
21
|
- **自动入口发现**: 无需手动配置每一个入口,Modulo 会自动扫描指定目录来发现项目的所有入口。
|
|
22
22
|
- **多框架支持**: 内置对 React、Vue 等流行框架的支持,并为 React 提供 `react-refresh` 等现代化开发体验。
|
|
23
23
|
- **零配置启动**: 通过 `modulo init` 命令快速初始化项目,自动生成配置文件和 `package.json` 脚本。
|
|
24
24
|
- **强大的开发服务器**: 内置高效的开发服务器,支持热模块替换(HMR)。
|
|
25
25
|
- **多种打包目标**: 支持将项目打包为**页面应用** (`page`) 或**独立的库** (`module`)。
|
|
26
|
-
-
|
|
26
|
+
- **自动 External**: 通过 `autoExternal` 功能,自动识别项目中使用的第三方库,并根据配置按需注入 Import Map 或 Script 标签,无需手动维护冗长的 HTML 模板。
|
|
27
|
+
- **灵活的产物格式**: 支持 `importmap` (ESM) 和 `script` (Global Variable) 两种 External 模式,适应不同的部署场景。
|
|
27
28
|
|
|
28
29
|
## 📦 先决条件
|
|
29
30
|
|
|
30
|
-
- [Node.js](https://nodejs.org/) (version
|
|
31
|
+
- [Node.js](https://nodejs.org/) (version 24+)
|
|
31
32
|
- [pnpm](https://pnpm.io/)
|
|
32
33
|
|
|
33
34
|
## 🚀 命令行接口 (CLI)
|
|
34
35
|
|
|
35
|
-
Modulo 提供 `init` 和 `pack` (`dev`/`build`)
|
|
36
|
+
Modulo 提供 `init` 和 `pack` (`dev`/`build`/`preview`) 两个核心命令组。
|
|
36
37
|
|
|
37
38
|
### `modulo init`
|
|
38
39
|
|
|
@@ -42,22 +43,23 @@ Modulo 提供 `init` 和 `pack` (`dev`/`build`) 两个核心命令。
|
|
|
42
43
|
|
|
43
44
|
- **`target` (必需):**
|
|
44
45
|
|
|
45
|
-
- `config`:
|
|
46
|
+
- `config`: 创建配置文件(支持 `modulo.config.ts`, `modulo.config.js`, `modulo.config.json`)。
|
|
46
47
|
- `script`: 在 `package.json` 中添加 `dev` 和 `build` 脚本。
|
|
48
|
+
- `project`: 初始化一个新的 Modulo 项目。
|
|
47
49
|
|
|
48
50
|
- **`options`:**
|
|
49
51
|
|
|
50
|
-
| 参数
|
|
51
|
-
|
|
|
52
|
-
| `--path <path>`
|
|
53
|
-
| `--force`
|
|
54
|
-
| `--preset <
|
|
52
|
+
| 参数 | 简写 | 描述 |
|
|
53
|
+
| :--- | :--- | :--- |
|
|
54
|
+
| `--path <path>` | | 指定配置文件的输出路径 (仅当 `target` 为 `config` 时有效),或者指定新项目的路径(仅当 `target` 为 `project` 时有效)。 |
|
|
55
|
+
| `--force` | `-f` | 强制覆盖现有文件 (仅当 `target` 为 `config` 时有效)。 |
|
|
56
|
+
| `--preset <preset>` | | 指定预设配置,目前支持 `react19`, `vue`, `vue2`。 |
|
|
55
57
|
|
|
56
|
-
### `modulo dev` / `modulo build`
|
|
58
|
+
### `modulo dev` / `modulo build` / `modulo preview`
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
用于启动开发服务器、执行生产构建或预览产物。
|
|
59
61
|
|
|
60
|
-
**用法:** `modulo <dev|build> <target> [options]`
|
|
62
|
+
**用法:** `modulo <dev|build|preview> <target> [options]`
|
|
61
63
|
|
|
62
64
|
- **`<target>` (位置参数, 必需):**
|
|
63
65
|
|
|
@@ -67,14 +69,13 @@ Modulo 提供 `init` 和 `pack` (`dev`/`build`) 两个核心命令。
|
|
|
67
69
|
|
|
68
70
|
- **`options`:**
|
|
69
71
|
|
|
70
|
-
| 参数
|
|
71
|
-
|
|
|
72
|
-
| `--env <dev\|prd>` |
|
|
73
|
-
| `--config <path>`
|
|
74
|
-
| `--watch`
|
|
75
|
-
| `--
|
|
76
|
-
| `--
|
|
77
|
-
| `--verbose` | `-v` | 显示更详细的日志信息。 |
|
|
72
|
+
| 参数 | 简写 | 描述 |
|
|
73
|
+
| :--- | :--- | :--- |
|
|
74
|
+
| `--env <dev\|prd>` | | 指定构建环境。`dev` 命令默认为 `dev`,`build` 命令默认为 `prd`。 |
|
|
75
|
+
| `--config <path>` | `-c` | 指定配置文件路径 (默认为 `modulo.config.ts`, `modulo.config.js`, `modulo.config.json` 之一)。 |
|
|
76
|
+
| `--watch` | `-w` | 在 `build` 模式下启用监听模式(对 `all` target 无效)。 |
|
|
77
|
+
| `--debug` | | 启用 Modulo 的调试日志,并在当前目录生成 `modulo.debug.log`。 |
|
|
78
|
+
| `--verbose` | `-v` | 在控制台显示更详细的日志信息。 |
|
|
78
79
|
|
|
79
80
|
## 🧠 核心概念:入口发现机制
|
|
80
81
|
|
|
@@ -82,7 +83,7 @@ Modulo 的一大特性是**自动入口发现**,您无需在配置文件中手
|
|
|
82
83
|
|
|
83
84
|
其工作方式如下:
|
|
84
85
|
|
|
85
|
-
1.
|
|
86
|
+
1. 在配置文件的 `input` 字段中,您需要定义 `pages` 和 `modules` 的根目录(例如 `src/pages` 或 `src/modules`)。
|
|
86
87
|
2. 当您运行 `modulo dev page` 或 `modulo dev module` 时,Modulo 会自动扫描 `input.pages` 或 `input.modules` 指定的目录。
|
|
87
88
|
3. 它会将每一个包含有效入口文件的**直接子目录**识别为一个独立的模块入口。
|
|
88
89
|
4. 对于每个子目录,Modulo 会按照以下优先级顺序查找入口文件:
|
|
@@ -95,7 +96,9 @@ Modulo 的一大特性是**自动入口发现**,您无需在配置文件中手
|
|
|
95
96
|
|
|
96
97
|
**示例**:对于一个名为 `src/pages/my-page` 的目录,如果项目是 Vue 框架,Modulo 可能会按 `index.ts` -> `index.vue` -> `my-page.vue` 的顺序查找入口文件。
|
|
97
98
|
|
|
98
|
-
## ⚙️ 配置文件 (`modulo.config.
|
|
99
|
+
## ⚙️ 配置文件 (`modulo.config.ts`)
|
|
100
|
+
|
|
101
|
+
Modulo 配置文件支持 `.ts`, `.js`, `.json` 格式。默认查找顺序为 `modulo.config.ts`, `modulo.config.js`, `modulo.config.json`。
|
|
99
102
|
|
|
100
103
|
这是 Modulo 的核心配置文件,提供了丰富的选项来满足各种定制化需求。
|
|
101
104
|
|
|
@@ -113,17 +116,6 @@ Modulo 的一大特性是**自动入口发现**,您无需在配置文件中手
|
|
|
113
116
|
- **特别说明**:
|
|
114
117
|
- 如果您的现有项目结构与 Modulo 的默认 `src/modules` 或 `src/pages` 不符,您可以直接修改这些路径以匹配您的项目。
|
|
115
118
|
- 另一种灵活的做法是,在符合 Modulo 预设的目录(例如 `src/pages/`)下,为旧项目中的模块创建新的入口文件(如 `index.ts`)。这些新的入口文件可以简单地从旧路径导出模块,从而在不侵入式修改旧代码的情况下,让 Modulo 能够识别并打包它们。
|
|
116
|
-
- **示例 (为旧项目模块创建 Modulo 兼容入口)**:
|
|
117
|
-
假设您的旧项目有一个位于 `old-project/components/Button.js` 的组件,并且您希望 Modulo 将其作为一个模块打包。
|
|
118
|
-
1. 在 `modulo.config.json` 中,确保 `input.modules` 指向 `src/modules` (或您自定义的模块目录)。
|
|
119
|
-
2. 在 `src/modules/my-button/` 目录下创建一个 `index.ts` 文件:
|
|
120
|
-
`typescript
|
|
121
|
-
// src/modules/my-button/index.ts
|
|
122
|
-
export { default as Button } from '../../old-project/components/Button.js';
|
|
123
|
-
// 或者,如果旧模块是命名导出:
|
|
124
|
-
// export * from '../../old-project/components/Button.js';
|
|
125
|
-
`
|
|
126
|
-
这样,Modulo 就会将 `src/modules/my-button` 识别为一个模块入口,并打包 `Button.js`。
|
|
127
119
|
|
|
128
120
|
### `output`
|
|
129
121
|
|
|
@@ -219,6 +211,25 @@ export { default as Button } from '../../old-project/components/Button.js';
|
|
|
219
211
|
|
|
220
212
|
---
|
|
221
213
|
|
|
214
|
+
### `autoExternal`
|
|
215
|
+
|
|
216
|
+
- **描述**: 是否开启自动 External 功能。开启后,Modulo 会自动扫描代码中引入的 `node_modules` 依赖,如果它们在 `externals` 中有定义,则自动注入对应的 Import Map 或 Script 标签。
|
|
217
|
+
- **类型**: `boolean`
|
|
218
|
+
- **默认值**: `true`。
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
### `externalsType`
|
|
223
|
+
|
|
224
|
+
- **描述**: 指定 External 的注入模式。
|
|
225
|
+
- **类型**: `"importmap" | "script"`
|
|
226
|
+
- **默认值**: `"importmap"`。
|
|
227
|
+
- **选项**:
|
|
228
|
+
- `importmap`: 使用原生的 Import Map 特性(需要浏览器支持或 polyfill),适合 ESM 现代开发模式。
|
|
229
|
+
- `script`: 将 External 映射为全局变量(如 `window.React`),适合传统 UMD 模式。
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
222
233
|
## 🌐 强大的 `externals` 配置
|
|
223
234
|
|
|
224
235
|
`externals` 是 Modulo 的一项核心功能,它允许您将一些体积较大、不常变动的第三方库(如 React, Vue, Lodash)从您的应用包中分离出去,改为通过 CDN 或其他外部服务器加载。
|
|
@@ -228,13 +239,14 @@ export { default as Button } from '../../old-project/components/Button.js';
|
|
|
228
239
|
- **减小包体积**: 显著减少主包大小,加快应用加载速度。
|
|
229
240
|
- **利用浏览器缓存**: 用户在访问不同应用时,可以复用已缓存的公共库。
|
|
230
241
|
- **加快构建速度**: 无需重复打包这些大型库。
|
|
242
|
+
- **按需注入**: 配合 `autoExternal: true`,只有当页面真正引用了某个库时,它的 CDN 链接才会被注入到 HTML 中。
|
|
231
243
|
|
|
232
244
|
### 工作原理
|
|
233
245
|
|
|
234
246
|
当您在 `externals` 中配置一个库时,Modulo 会执行两个关键操作:
|
|
235
247
|
|
|
236
248
|
1. **告知打包器**: 它会配置底层的打包器(Rspack),告诉它在代码中遇到 `import React from 'react'` 这样的语句时,不要将 `react` 库打包进来,而是将其视为一个“外部的”、在运行时已经存在的依赖。
|
|
237
|
-
2. **自动注入脚本**: 对于 `page` 类型的入口,Modulo 会读取 `externals` 的配置,并自动在生成的 HTML 文件中注入相应的 `<script>`
|
|
249
|
+
2. **自动注入脚本**: 对于 `page` 类型的入口,Modulo 会读取 `externals` 的配置,并自动在生成的 HTML 文件中注入相应的 `<script>` 标签(Import Map 或普通 Script),以从您指定的 URL 加载这个库。
|
|
238
250
|
|
|
239
251
|
### 配置详解
|
|
240
252
|
|
|
@@ -255,10 +267,7 @@ export { default as Button } from '../../old-project/components/Button.js';
|
|
|
255
267
|
"externals": {
|
|
256
268
|
"react-dom": {
|
|
257
269
|
"importName": ["react-dom", "ReactDOM"],
|
|
258
|
-
"url":
|
|
259
|
-
"umd": "/packages/common/js/react-17.0.2/umd/react-dom.production.min.js",
|
|
260
|
-
"esm": "https://cdn.jsdelivr.net/npm/react-dom@17.0.2/+esm"
|
|
261
|
-
}
|
|
270
|
+
"url": "https://esm.sh/react-dom@19.2.4"
|
|
262
271
|
}
|
|
263
272
|
}
|
|
264
273
|
```
|
|
@@ -268,32 +277,27 @@ export { default as Button } from '../../old-project/components/Button.js';
|
|
|
268
277
|
- **`url`** (`string | object`, 必需):
|
|
269
278
|
- **作用**: 指定库的加载地址。
|
|
270
279
|
- **字符串形式**: 如果是字符串,则在所有模式下都使用该 URL。
|
|
271
|
-
- **对象形式**:
|
|
272
|
-
- `umd` (`string`): 提供 UMD (Universal Module Definition) 格式的库 URL。这是传统的、可以通过 `<script>` 标签直接加载并在全局(如 `window.ReactDOM`)暴露变量的格式。
|
|
273
|
-
- `esm` (`string`): 提供 ES Module 格式的库 URL。当您使用 `--format esm` 构建时,Modulo 会使用此 URL,并通过 `importmap` 机制来加载模块。
|
|
274
280
|
- **dev 和 prd 模式**
|
|
275
|
-
- 对 url
|
|
281
|
+
- 对 url 对象进行嵌套,以分别指定 dev 和 prd 模式下的 URL。
|
|
276
282
|
|
|
277
283
|
## 外部依赖加载
|
|
278
284
|
|
|
279
285
|
当 `modulo` 打包您的应用程序时,它会以特定的方式处理外部依赖项,以支持模块化加载和高效缓存。外部依赖项(如 React、Vue、jQuery 等)不会直接打包到您的模块输出中。相反,它们期望在运行时由宿主环境提供。
|
|
280
286
|
|
|
281
|
-
这主要通过 **
|
|
287
|
+
这主要通过 **Import Maps (ESM)** 或 **Global Variables (UMD)** 进行管理,具体取决于 `externalsType` 的配置。
|
|
282
288
|
|
|
283
|
-
###
|
|
289
|
+
### Import Maps (推荐)
|
|
284
290
|
|
|
285
291
|
导入映射是一个 JSON 对象,允许您控制模块说明符的解析。在 `modulo` 的上下文中,您可以在 `index.html`(或类似的入口文件)中的导入映射中定义您的外部依赖项及其对应的 URL。
|
|
286
292
|
|
|
287
293
|
**导入映射示例:**
|
|
288
294
|
|
|
289
295
|
```html
|
|
290
|
-
<script type="
|
|
296
|
+
<script type="importmap">
|
|
291
297
|
{
|
|
292
298
|
"imports": {
|
|
293
|
-
"react": "https://
|
|
294
|
-
"react-dom": "
|
|
295
|
-
"vue": "https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js",
|
|
296
|
-
"jquery": "https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"
|
|
299
|
+
"react": "https://esm.sh/react@19.2.4",
|
|
300
|
+
"react-dom": "https://esm.sh/react-dom@19.2.4"
|
|
297
301
|
}
|
|
298
302
|
}
|
|
299
303
|
</script>
|
|
@@ -301,11 +305,4 @@ export { default as Button } from '../../old-project/components/Button.js';
|
|
|
301
305
|
|
|
302
306
|
在此示例中:
|
|
303
307
|
|
|
304
|
-
- 当您的打包模块尝试 `import 'react'`
|
|
305
|
-
- 本地路径,例如此示例中的 `react-dom` 或 `vue`,如果依赖项托管在本地或您的项目结构中,也可以使用。
|
|
306
|
-
|
|
307
|
-
### `webhost` 的作用
|
|
308
|
-
|
|
309
|
-
`webhost` 库(位于 `packages/webhost`)旨在与此外部依赖加载机制协同工作。**`webhost` 会通过 `modulo.config.json` 中 `html.tags` 配置项自动注入到所有页面应用中,以提供开箱即用的模块加载能力。** 它提供了一组实用函数,通过 `window.webhost.remote_module` 对象暴露,可简化加载和挂载依赖于这些外部框架的模块的过程。
|
|
310
|
-
|
|
311
|
-
`window.webhost.remote_module.mount` 函数内部使用 SystemJS 导入指定的模块及其依赖项(通过导入映射解析),然后处理初始化和挂载的框架特定逻辑,并能自动识别 React 或 Vue 组件。此外,还提供了 `mount_react` 和 `mount_vue2` 等特定框架的挂载函数。
|
|
308
|
+
- 当您的打包模块尝试 `import React from 'react'` 时,浏览器会将其解析为 `https://esm.sh/react@19.2.4`。
|
package/bin/modulo.js
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
|
+
const requiredVersion = 24;
|
|
4
|
+
const currentVersion = process.version.match(/^v(\d+)/)?.[1];
|
|
5
|
+
|
|
6
|
+
if (!currentVersion || parseInt(currentVersion) < requiredVersion) {
|
|
7
|
+
console.error(
|
|
8
|
+
`\x1b[31mError: Node.js version ${process.version} is not supported. Please use Node.js v${requiredVersion} or higher.\x1b[0m`,
|
|
9
|
+
);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
import("../src/index.ts")
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
.then((module) => {
|
|
15
|
+
// console.log("\nsupport ts, use Typescript code\n");
|
|
16
|
+
try {
|
|
17
|
+
module.exec();
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.error(e);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
.catch((e) => {
|
|
24
|
+
console.error(
|
|
25
|
+
"\x1b[31mError: Failed to load TypeScript source code.\x1b[0m",
|
|
26
|
+
);
|
|
27
|
+
console.error(e);
|
|
28
|
+
console.error(
|
|
29
|
+
`\x1b[33mTip: Ensure you are running with Node.js v${requiredVersion}+ which supports TypeScript natively (experimental).\x1b[0m`,
|
|
30
|
+
);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
});
|
package/biome.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.4.4/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": false,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": false
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": false
|
|
10
|
+
},
|
|
11
|
+
"formatter": {
|
|
12
|
+
"enabled": true,
|
|
13
|
+
"indentStyle": "tab"
|
|
14
|
+
},
|
|
15
|
+
"linter": {
|
|
16
|
+
"enabled": true,
|
|
17
|
+
"rules": {
|
|
18
|
+
"recommended": true
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"javascript": {
|
|
22
|
+
"formatter": {
|
|
23
|
+
"quoteStyle": "double"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"assist": {
|
|
27
|
+
"enabled": true,
|
|
28
|
+
"actions": {
|
|
29
|
+
"source": {
|
|
30
|
+
"organizeImports": "on"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
2
|
+
"name": "@yannick-z/modulo",
|
|
3
|
+
"description": "",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.3.1",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"author": "oyangxiao",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "直接使用ts执行,所以不需要build",
|
|
10
|
+
"lint": "biome lint .",
|
|
11
|
+
"format": "biome format --write .",
|
|
12
|
+
"check": "biome check --write ."
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"modulo": "./bin/modulo.js"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@rsbuild/core": "^1.7.3",
|
|
19
|
+
"@rsbuild/plugin-less": "^1.6.0",
|
|
20
|
+
"@rsbuild/plugin-react": "^1.4.5",
|
|
21
|
+
"@rsbuild/plugin-vue2": "^1.1.0",
|
|
22
|
+
"@rslib/core": "^0.19.6",
|
|
23
|
+
"@types/node": "^24.0.0",
|
|
24
|
+
"cac": "^6.7.14",
|
|
25
|
+
"picocolors": "^1.1.1",
|
|
26
|
+
"semver": "^7.7.2",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@biomejs/biome": "2.4.4",
|
|
31
|
+
"@types/semver": "^7.7.1"
|
|
32
|
+
},
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/rslib.config.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
1
|
+
import { defineConfig } from "@rslib/core";
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
lib: [
|
|
5
|
+
{
|
|
6
|
+
dts: false,
|
|
7
|
+
format: "esm",
|
|
8
|
+
syntax: "esnext",
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
output: {
|
|
12
|
+
distPath: {
|
|
13
|
+
root: "./dist",
|
|
14
|
+
},
|
|
15
|
+
target: "node",
|
|
16
|
+
},
|
|
17
|
+
source: {
|
|
18
|
+
entry: {
|
|
19
|
+
index: "./src/index.ts",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
22
|
});
|
|
@@ -4,16 +4,16 @@ import { PANIC_IF } from "../tools/panic.ts";
|
|
|
4
4
|
import semver from "semver";
|
|
5
5
|
|
|
6
6
|
export function detect_preset() {
|
|
7
|
-
|
|
7
|
+
const { dependencies } = get_packagejson();
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const framework_name = get_framework_name();
|
|
10
|
+
const version = semver.parse(dependencies[framework_name])!;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
PANIC_IF(!version, `package.json中未识别到${framework_name}的版本信息`);
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
//需要识别
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const preset = `${framework_name}${version.major}`;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
return preset;
|
|
19
19
|
}
|
package/src/args/index.ts
CHANGED
|
@@ -1,80 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { default_config_file_name } from "../config/example/example-config.ts";
|
|
3
|
-
import type { preset_ui_libs } from "../config/preset/libs.ts";
|
|
4
|
-
import { get_cmd, type ModuloCmd_Init, type ModuloCmd_Pack } from "./cmd.ts";
|
|
5
|
-
import { get_env } from "./mode.ts";
|
|
6
|
-
import { set_node_env } from "./node_env.ts";
|
|
7
|
-
import { get_preset_for_init } from "./preset.ts";
|
|
8
|
-
import {
|
|
9
|
-
get_cmd_target,
|
|
10
|
-
type ModuloTarget_Init,
|
|
11
|
-
type ModuloTarget_Pack,
|
|
12
|
-
} from "./target.ts";
|
|
1
|
+
import type { preset_ui_libs } from "../config/presets.ts";
|
|
13
2
|
|
|
14
3
|
export interface ModuloArgs_Pack {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
cmd: "build" | "dev" | "preview";
|
|
5
|
+
target: "page" | "module" | "all";
|
|
6
|
+
pack: {
|
|
7
|
+
config?: string;
|
|
8
|
+
env: "dev" | "prd";
|
|
9
|
+
watch: boolean;
|
|
10
|
+
esm: boolean;
|
|
11
|
+
};
|
|
23
12
|
}
|
|
24
13
|
|
|
25
14
|
export interface ModuloArgs_Init {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let args: ModuloArgs_Init | ModuloArgs_Pack;
|
|
36
|
-
|
|
37
|
-
const argv = minimist(process.argv.slice(2));
|
|
38
|
-
export const argv_debug = argv.debug === "true";
|
|
39
|
-
export const argv_verbose = argv.verbose === "true" || argv.v;
|
|
40
|
-
|
|
41
|
-
export function get_args() {
|
|
42
|
-
if (!args) {
|
|
43
|
-
const cmd = get_cmd(argv);
|
|
44
|
-
|
|
45
|
-
if (cmd === "build" || cmd === "dev") {
|
|
46
|
-
const target = get_cmd_target(argv, cmd);
|
|
47
|
-
// watch只能对单个构建目标使用
|
|
48
|
-
const watch = target === "all" ? false : argv.watch === "true" || argv.w;
|
|
49
|
-
args = {
|
|
50
|
-
cmd,
|
|
51
|
-
target,
|
|
52
|
-
// 是否是调试modulo
|
|
53
|
-
pack: {
|
|
54
|
-
// 配置文件路径
|
|
55
|
-
config:
|
|
56
|
-
(argv.config as string | undefined) || default_config_file_name,
|
|
57
|
-
// 运行模式, dev | prd
|
|
58
|
-
env: cmd === "build" || cmd === "dev" ? get_env(argv, cmd) : "prd",
|
|
59
|
-
watch,
|
|
60
|
-
esm: argv.format === "esm" || argv.f === "esm",
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
args.pack.env && set_node_env(args.pack.env);
|
|
64
|
-
} else {
|
|
65
|
-
args = {
|
|
66
|
-
cmd,
|
|
67
|
-
target: get_cmd_target(argv, cmd),
|
|
68
|
-
init: {
|
|
69
|
-
path: argv.path,
|
|
70
|
-
force: argv.force === "true" || argv.f,
|
|
71
|
-
preset: get_preset_for_init(argv),
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (argv_verbose) console.log("args: ", args);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return args;
|
|
15
|
+
cmd: "init";
|
|
16
|
+
target: "config" | "script" | "project";
|
|
17
|
+
init: {
|
|
18
|
+
path: string;
|
|
19
|
+
force: boolean;
|
|
20
|
+
preset: keyof typeof preset_ui_libs;
|
|
21
|
+
};
|
|
80
22
|
}
|
package/src/args/preset.ts
CHANGED
|
@@ -4,23 +4,23 @@ import { detect_preset } from "./get-framework-name.ts";
|
|
|
4
4
|
import { PANIC_IF } from "../tools/panic.ts";
|
|
5
5
|
|
|
6
6
|
export function get_preset_for_init(argv: minimist.ParsedArgs) {
|
|
7
|
-
|
|
7
|
+
let preset = argv.preset;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
if (!preset) {
|
|
10
|
+
preset = detect_preset();
|
|
11
|
+
console.log(
|
|
12
|
+
picocolors.blue(
|
|
13
|
+
"未输入preset,但是根据package.json中的依赖自动识别到preset为: " +
|
|
14
|
+
preset,
|
|
15
|
+
),
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
preset &&
|
|
20
|
+
PANIC_IF(
|
|
21
|
+
preset !== "react17" && preset !== "react19" && preset !== "vue2",
|
|
22
|
+
"目前只支持react17, react19和vue2",
|
|
23
|
+
);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
return preset;
|
|
26
26
|
}
|
package/src/cli/init.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { ModuloArgs_Init } from "../args/index.ts";
|
|
2
2
|
import { create_config_file } from "../initiator/create-config-file.ts";
|
|
3
3
|
import { modify_scripts } from "../initiator/modify-scripts.ts";
|
|
4
|
+
import { create_project } from "../initiator/create-project.ts";
|
|
4
5
|
|
|
5
6
|
export function init_tool(args: ModuloArgs_Init) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
if (args.target === "config") {
|
|
8
|
+
create_config_file(args);
|
|
9
|
+
}
|
|
10
|
+
if (args.target === "script") {
|
|
11
|
+
modify_scripts();
|
|
12
|
+
}
|
|
13
|
+
if (args.target === "project") {
|
|
14
|
+
create_project(args);
|
|
15
|
+
}
|
|
12
16
|
}
|