@path-ioc/pack 0.1.3 → 0.1.5
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 +26 -7
- package/README.zh-CN.md +25 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,12 +15,16 @@
|
|
|
15
15
|
</p>
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
|
+
> 💡 **Architectural Positioning & Usage Boundary**
|
|
19
|
+
> `@path-ioc/pack` is a dedicated Vite build plugin designed to bundle an isolated Mesh module directory into a **distributable standalone npm package / component library**.
|
|
20
|
+
> **Warning**: This plugin automatically intercepts Vite configuration and forces Library Mode (`build.lib`). **Do NOT unconditionally embed it in standard web application builds (e.g. standard Vite SPA/SSR configs).** It is recommended to use a dedicated packaging config (e.g. `vite.config.pack.ts`) or trigger it via separate packaging scripts.
|
|
21
|
+
|
|
18
22
|
---
|
|
19
23
|
|
|
20
|
-
##
|
|
24
|
+
## Core Capabilities
|
|
21
25
|
|
|
22
26
|
- **Physical Entrypoint Generation**:
|
|
23
|
-
During Vite builds, automatically scans `src/modules` for physical directories containing `index.ts/tsx` and synthesizes clean on-disk entrypoints (default
|
|
27
|
+
During Vite builds, automatically scans `src/modules` for physical directories containing `index.ts/tsx` and synthesizes clean on-disk entrypoints (default `node_modules/.path-ioc/.modular-plugin-entry.ts`);
|
|
24
28
|
- **Full Mesh Registry & Type Exports**:
|
|
25
29
|
Generates unified module import aliases and exports the canonical runtime module registry array `modules`:
|
|
26
30
|
```typescript
|
|
@@ -30,9 +34,11 @@
|
|
|
30
34
|
];
|
|
31
35
|
```
|
|
32
36
|
- **Static Type Mapping Extraction (`sharedMappings`)**:
|
|
33
|
-
|
|
34
|
-
- **
|
|
35
|
-
|
|
37
|
+
Populates `sharedMappings` and `sharedContainerMappings` arrays to provide accurate type descriptions for cross-package SDKs or microfrontend mesh topologies;
|
|
38
|
+
- **Built-in Obfuscation Protection**:
|
|
39
|
+
During the `closeBundle` lifecycle, automatically performs deep code obfuscation using `javascript-obfuscator` by default. Can be disabled via environment variable `MODULAR_OBFUSCATE=false`;
|
|
40
|
+
- **Automated Packaging**:
|
|
41
|
+
Automatically synthesizes package-ready metadata (`package.json`, `index.d.ts`) and triggers `npm pack` in `outDir` to produce distribution `.tgz` tarballs.
|
|
36
42
|
|
|
37
43
|
---
|
|
38
44
|
|
|
@@ -48,7 +54,7 @@ npm install -D @path-ioc/pack
|
|
|
48
54
|
|
|
49
55
|
## Quick Start
|
|
50
56
|
|
|
51
|
-
###
|
|
57
|
+
### Dedicated Packaging Config (`vite.config.pack.ts`)
|
|
52
58
|
|
|
53
59
|
```typescript
|
|
54
60
|
import { defineConfig } from "vite";
|
|
@@ -61,7 +67,8 @@ export default defineConfig({
|
|
|
61
67
|
plugins: [
|
|
62
68
|
modularPackPlugin({
|
|
63
69
|
modulesPath: "src/modules",
|
|
64
|
-
|
|
70
|
+
outDir: "dist-plugin",
|
|
71
|
+
// Optional: Custom on-disk entrypoint path
|
|
65
72
|
entryFile: "node_modules/.path-ioc/.modular-plugin-entry.ts",
|
|
66
73
|
sharedMappings,
|
|
67
74
|
sharedContainerMappings,
|
|
@@ -70,6 +77,11 @@ export default defineConfig({
|
|
|
70
77
|
});
|
|
71
78
|
```
|
|
72
79
|
|
|
80
|
+
To build and package your mesh bundle:
|
|
81
|
+
```bash
|
|
82
|
+
vite build --config vite.config.pack.ts
|
|
83
|
+
```
|
|
84
|
+
|
|
73
85
|
---
|
|
74
86
|
|
|
75
87
|
## Configuration Options (`PackPluginOptions`)
|
|
@@ -78,11 +90,18 @@ export default defineConfig({
|
|
|
78
90
|
| :--- | :--- | :--- | :--- |
|
|
79
91
|
| **`modulesPath`** | `string` | `'src/modules'` | Root directory scanned for modular IoC entrypoints. |
|
|
80
92
|
| **`entryFile`** | `string` | `'node_modules/.path-ioc/.modular-plugin-entry.ts'` | Target physical path for the generated entrypoint file. |
|
|
93
|
+
| **`outDir`** | `string` | `'dist-plugin'` | Output directory for the packaged library bundle and npm tarball. |
|
|
81
94
|
| **`sharedMappings`** | `string[]` | `[]` *(optional)* | Reference to an array that receives generated type mapping strings. |
|
|
82
95
|
| **`sharedContainerMappings`** | `string[]` | `[]` *(optional)* | Reference to an array that receives generated container type mapping strings. |
|
|
83
96
|
|
|
84
97
|
---
|
|
85
98
|
|
|
99
|
+
## Environment Variables
|
|
100
|
+
|
|
101
|
+
- **`MODULAR_OBFUSCATE`**: Set to `false` (e.g. `MODULAR_OBFUSCATE=false vite build`) to disable the default `javascript-obfuscator` pass for debugging or open-source distribution.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
86
105
|
## Exported API
|
|
87
106
|
|
|
88
107
|
```typescript
|
package/README.zh-CN.md
CHANGED
|
@@ -15,12 +15,16 @@
|
|
|
15
15
|
</p>
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
|
+
> 💡 **架构定位与使用边界警告**
|
|
19
|
+
> `@path-ioc/pack` 是专用于将 Mesh 模块目录打包为**独立发布的 npm 插件包/组件库**的专用 Vite 构建插件。
|
|
20
|
+
> **警告**:该插件会在构建期自动接管改写 Vite 的 Library 模式(`build.lib`)。**严禁无条件直接写入通用 Web 前端应用(如 SPA/SSR)的主构建配置中。** 推荐通过独立的打包配置(例如 `vite.config.pack.ts`)或专属构建脚本按需触发。
|
|
21
|
+
|
|
18
22
|
---
|
|
19
23
|
|
|
20
24
|
## 核心特性 (Features)
|
|
21
25
|
|
|
22
26
|
- **物理入口自动生成 (Physical Entrypoint Generation)**:
|
|
23
|
-
在 Vite 构建流程中,自动深度扫描 `src/modules` 下所有包含 `index.ts/tsx`
|
|
27
|
+
在 Vite 构建流程中,自动深度扫描 `src/modules` 下所有包含 `index.ts/tsx` 的物理子目录,并在磁盘上自动生成/更新入口文件(默认 `node_modules/.path-ioc/.modular-plugin-entry.ts`);
|
|
24
28
|
- **Mesh 注册表与类型全导出**:
|
|
25
29
|
自动生成统一的模块导入别名与导出,并导出标准运行期注册表数组 `modules`:
|
|
26
30
|
```typescript
|
|
@@ -30,9 +34,11 @@
|
|
|
30
34
|
];
|
|
31
35
|
```
|
|
32
36
|
- **静态类型映射提取 (`sharedMappings`)**:
|
|
33
|
-
自动填充 `sharedMappings` 与 `sharedContainerMappings` 集合,为构建跨包 SDK
|
|
34
|
-
-
|
|
35
|
-
|
|
37
|
+
自动填充 `sharedMappings` 与 `sharedContainerMappings` 集合,为构建跨包 SDK 或微前端网格映射提供准确的类型描述;
|
|
38
|
+
- **内置源码深度混淆保护**:
|
|
39
|
+
构建结束时(`closeBundle` 生命周期)默认集成 `javascript-obfuscator` 对产物代码进行深度混淆保护,可通过环境变量 `MODULAR_OBFUSCATE=false` 关闭;
|
|
40
|
+
- **交付包全自动打包**:
|
|
41
|
+
自动生成交付标准的 `package.json` 与 `index.d.ts` 类型声明,并自动在 `outDir` 目录调用 `npm pack` 产出可分发的 `.tgz` 压缩包。
|
|
36
42
|
|
|
37
43
|
---
|
|
38
44
|
|
|
@@ -48,7 +54,7 @@ npm install -D @path-ioc/pack
|
|
|
48
54
|
|
|
49
55
|
## 快速上手 (Quick Start)
|
|
50
56
|
|
|
51
|
-
### Vite
|
|
57
|
+
### 专属 Vite 打包配置 (`vite.config.pack.ts`)
|
|
52
58
|
|
|
53
59
|
```typescript
|
|
54
60
|
import { defineConfig } from "vite";
|
|
@@ -61,7 +67,8 @@ export default defineConfig({
|
|
|
61
67
|
plugins: [
|
|
62
68
|
modularPackPlugin({
|
|
63
69
|
modulesPath: "src/modules",
|
|
64
|
-
|
|
70
|
+
outDir: "dist-plugin",
|
|
71
|
+
// 可选:自定义生成的入口文件路径
|
|
65
72
|
entryFile: "node_modules/.path-ioc/.modular-plugin-entry.ts",
|
|
66
73
|
sharedMappings,
|
|
67
74
|
sharedContainerMappings,
|
|
@@ -70,6 +77,11 @@ export default defineConfig({
|
|
|
70
77
|
});
|
|
71
78
|
```
|
|
72
79
|
|
|
80
|
+
执行打包命令:
|
|
81
|
+
```bash
|
|
82
|
+
vite build --config vite.config.pack.ts
|
|
83
|
+
```
|
|
84
|
+
|
|
73
85
|
---
|
|
74
86
|
|
|
75
87
|
## 配置选项 (PackPluginOptions)
|
|
@@ -78,11 +90,18 @@ export default defineConfig({
|
|
|
78
90
|
| :--- | :--- | :--- | :--- |
|
|
79
91
|
| **`modulesPath`** | `string` | `'src/modules'` | 模块扫描的物理根目录路径。 |
|
|
80
92
|
| **`entryFile`** | `string` | `'node_modules/.path-ioc/.modular-plugin-entry.ts'` | 物理生成的入口文件路径。 |
|
|
93
|
+
| **`outDir`** | `string` | `'dist-plugin'` | 构建产物输出与 npm 打包目录。 |
|
|
81
94
|
| **`sharedMappings`** | `string[]` | `[]` *(可选)* | 接收生成的类型映射字符串数组引用。 |
|
|
82
95
|
| **`sharedContainerMappings`** | `string[]` | `[]` *(可选)* | 接收生成的容器类型映射字符串数组引用。 |
|
|
83
96
|
|
|
84
97
|
---
|
|
85
98
|
|
|
99
|
+
## 环境变量 (Environment Variables)
|
|
100
|
+
|
|
101
|
+
- **`MODULAR_OBFUSCATE`**:设置为 `false`(例如 `MODULAR_OBFUSCATE=false vite build --config vite.config.pack.ts`)可关闭默认的 `javascript-obfuscator` 混淆步骤,便于本地调试或开源包发布。
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
86
105
|
## 导出的 API
|
|
87
106
|
|
|
88
107
|
```typescript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@path-ioc/pack",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Mesh registry distribution bundler & obfuscator for Path-IoC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ioc",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@path-ioc/unplugin": "0.1.
|
|
53
|
+
"@path-ioc/unplugin": "0.1.5",
|
|
54
54
|
"@types/node": "^20.0.0",
|
|
55
55
|
"tsup": "^8.0.0",
|
|
56
56
|
"typescript": "^5.4.5",
|