@meng-xi/vite-plugin 0.0.3 → 0.0.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-en.md +182 -150
- package/README.md +182 -84
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +207 -6
- package/dist/common/index.d.mts +207 -6
- package/dist/common/index.d.ts +207 -6
- package/dist/common/index.mjs +1 -1
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/logger/index.cjs +1 -1
- package/dist/logger/index.mjs +1 -1
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +296 -1
- package/dist/plugins/index.d.mts +296 -1
- package/dist/plugins/index.d.ts +296 -1
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/vite-plugin.B88RyRN8.mjs +3 -0
- package/dist/shared/vite-plugin.BZsetDCm.cjs +1 -0
- package/dist/shared/vite-plugin.C7isVPKg.mjs +1 -0
- package/dist/shared/vite-plugin.CS9a5kjK.mjs +36 -0
- package/dist/shared/vite-plugin.CgnG5_UX.cjs +36 -0
- package/dist/shared/vite-plugin.DqWt65U-.cjs +1 -0
- package/dist/shared/vite-plugin.IGZeStMa.cjs +3 -0
- package/dist/shared/vite-plugin.YvjM8LxW.mjs +1 -0
- package/package.json +72 -72
- package/dist/shared/vite-plugin.BT1oHRKK.cjs +0 -1
- package/dist/shared/vite-plugin.BTKhc7n7.cjs +0 -3
- package/dist/shared/vite-plugin.BZqhBDYR.mjs +0 -1
- package/dist/shared/vite-plugin.Bn8mcCzy.cjs +0 -3
- package/dist/shared/vite-plugin.CY2ydccp.mjs +0 -3
- package/dist/shared/vite-plugin.ClHiVXD6.mjs +0 -1
- package/dist/shared/vite-plugin.DSRKYuae.mjs +0 -3
- package/dist/shared/vite-plugin.DrSzERYS.cjs +0 -1
package/README-en.md
CHANGED
|
@@ -1,150 +1,182 @@
|
|
|
1
|
-
**English** | [中文](./README.md)
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
<a href="https://github.com/MengXi-Studio/vite-plugin">
|
|
5
|
-
<img alt="
|
|
6
|
-
</a>
|
|
7
|
-
<br>
|
|
8
|
-
<h1>@meng-xi/vite-plugin</h1>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-

|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://github.com/MengXi-Studio/vite-plugin">
|
|
5
|
+
<img alt="MengXi Studio Logo" width="215" src="https://github.com/MengXi-Studio/vite-plugin/blob/master/packages/docs/src/public/logo.svg">
|
|
6
|
+
</a>
|
|
7
|
+
<br>
|
|
8
|
+
<h1>@meng-xi/vite-plugin</h1>
|
|
9
|
+
<p>A toolkit providing practical plugins for Vite, also a complete plugin development framework</p>
|
|
10
|
+
|
|
11
|
+
[](LICENSE) [](https://www.npmjs.com/package/@meng-xi/vite-plugin)
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Ready to Use** - Provides practical plugins for file copying, router generation, version management, icon injection
|
|
19
|
+
- **Plugin Development Framework** - Exports core components like BasePlugin, Logger, Validator for building custom plugins
|
|
20
|
+
- **Type Safe** - Complete TypeScript type definitions with configuration validators ensuring parameter correctness
|
|
21
|
+
- **Flexible Configuration** - All plugins support detailed configuration to meet diverse scenario requirements
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
View full documentation: [https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# npm
|
|
31
|
+
npm install @meng-xi/vite-plugin -D
|
|
32
|
+
|
|
33
|
+
# yarn
|
|
34
|
+
yarn add @meng-xi/vite-plugin -D
|
|
35
|
+
|
|
36
|
+
# pnpm
|
|
37
|
+
pnpm add @meng-xi/vite-plugin -D
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### Using Built-in Plugins
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { defineConfig } from 'vite'
|
|
46
|
+
import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
|
|
47
|
+
|
|
48
|
+
export default defineConfig({
|
|
49
|
+
plugins: [
|
|
50
|
+
// Copy files
|
|
51
|
+
copyFile({
|
|
52
|
+
sourceDir: 'src/assets',
|
|
53
|
+
targetDir: 'dist/assets'
|
|
54
|
+
}),
|
|
55
|
+
|
|
56
|
+
// Generate router config (uni-app)
|
|
57
|
+
generateRouter({
|
|
58
|
+
pagesJsonPath: 'src/pages.json',
|
|
59
|
+
outputPath: 'src/router.config.ts'
|
|
60
|
+
}),
|
|
61
|
+
|
|
62
|
+
// Generate version
|
|
63
|
+
generateVersion({
|
|
64
|
+
format: 'datetime',
|
|
65
|
+
outputType: 'both'
|
|
66
|
+
}),
|
|
67
|
+
|
|
68
|
+
// Inject website icon
|
|
69
|
+
injectIco({
|
|
70
|
+
base: '/assets'
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Developing Custom Plugins
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
|
|
80
|
+
import type { Plugin } from 'vite'
|
|
81
|
+
|
|
82
|
+
interface MyPluginOptions {
|
|
83
|
+
path: string
|
|
84
|
+
enabled?: boolean
|
|
85
|
+
verbose?: boolean
|
|
86
|
+
errorStrategy?: 'throw' | 'log' | 'ignore'
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class MyPlugin extends BasePlugin<MyPluginOptions> {
|
|
90
|
+
protected getDefaultOptions() {
|
|
91
|
+
return { path: './default' }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected validateOptions(): void {
|
|
95
|
+
this.validator.field('path').required().string().validate()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected getPluginName(): string {
|
|
99
|
+
return 'my-plugin'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
protected addPluginHooks(plugin: Plugin): void {
|
|
103
|
+
plugin.buildStart = () => {
|
|
104
|
+
this.logger.info(`Plugin started with path: ${this.options.path}`)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const myPlugin = createPluginFactory(MyPlugin)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Built-in Plugins
|
|
113
|
+
|
|
114
|
+
### copyFile
|
|
115
|
+
|
|
116
|
+
Copy files or directories to specified locations after Vite build is completed.
|
|
117
|
+
|
|
118
|
+
| Option | Type | Default | Description |
|
|
119
|
+
| ----------- | ------- | ------- | ------------------------------------------ |
|
|
120
|
+
| sourceDir | string | - | Source directory path (required) |
|
|
121
|
+
| targetDir | string | - | Target directory path (required) |
|
|
122
|
+
| overwrite | boolean | true | Whether to overwrite existing files |
|
|
123
|
+
| recursive | boolean | true | Whether to recursively copy subdirectories |
|
|
124
|
+
| incremental | boolean | true | Whether to enable incremental copying |
|
|
125
|
+
|
|
126
|
+
### generateRouter
|
|
127
|
+
|
|
128
|
+
Automatically generate router configuration files based on uni-app project's `pages.json`.
|
|
129
|
+
|
|
130
|
+
| Option | Type | Default | Description |
|
|
131
|
+
| -------------------- | ------------ | ---------------------- | ------------------------------------------------ |
|
|
132
|
+
| pagesJsonPath | string | 'src/pages.json' | Path to pages.json file |
|
|
133
|
+
| outputPath | string | 'src/router.config.ts' | Output file path |
|
|
134
|
+
| outputFormat | 'ts' \| 'js' | 'ts' | Output file format |
|
|
135
|
+
| nameStrategy | string | 'camelCase' | Route name strategy |
|
|
136
|
+
| includeSubPackages | boolean | true | Whether to include sub-package routes |
|
|
137
|
+
| watch | boolean | true | Whether to watch changes and auto-regenerate |
|
|
138
|
+
| metaMapping | object | - | Mapping from page style fields to meta |
|
|
139
|
+
| preserveRouteChanges | boolean | true | Whether to preserve user modifications to routes |
|
|
140
|
+
|
|
141
|
+
### generateVersion
|
|
142
|
+
|
|
143
|
+
Automatically generate version numbers during the Vite build process.
|
|
144
|
+
|
|
145
|
+
| Option | Type | Default | Description |
|
|
146
|
+
| ---------- | ------ | --------------------- | ------------------------------ |
|
|
147
|
+
| format | string | 'timestamp' | Version format |
|
|
148
|
+
| outputType | string | 'file' | Output type |
|
|
149
|
+
| outputFile | string | 'version.json' | Output file path |
|
|
150
|
+
| defineName | string | '\_\_APP_VERSION\_\_' | Global variable name to inject |
|
|
151
|
+
| prefix | string | - | Version number prefix |
|
|
152
|
+
| suffix | string | - | Version number suffix |
|
|
153
|
+
|
|
154
|
+
### injectIco
|
|
155
|
+
|
|
156
|
+
Inject website icon links into the head of HTML files during the Vite build process.
|
|
157
|
+
|
|
158
|
+
| Option | Type | Default | Description |
|
|
159
|
+
| ----------- | ------ | ------- | ------------------------------- |
|
|
160
|
+
| base | string | - | Base path for icon files |
|
|
161
|
+
| url | string | - | Complete URL for the icon |
|
|
162
|
+
| link | string | - | Custom complete link tag HTML |
|
|
163
|
+
| icons | array | - | Custom icon array |
|
|
164
|
+
| copyOptions | object | - | Icon file copying configuration |
|
|
165
|
+
|
|
166
|
+
## Changelog
|
|
167
|
+
|
|
168
|
+
See [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
|
|
169
|
+
|
|
170
|
+
## Contributing
|
|
171
|
+
|
|
172
|
+
Contributions are welcome! Please follow these steps:
|
|
173
|
+
|
|
174
|
+
1. Fork the repository
|
|
175
|
+
2. Create a feature branch: `git checkout -b feature/your-feature`
|
|
176
|
+
3. Commit changes: `git commit -m "feat: your feature description"`
|
|
177
|
+
4. Push to branch: `git push origin feature/your-feature`
|
|
178
|
+
5. Create a Pull Request
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
[MIT](LICENSE)
|
package/README.md
CHANGED
|
@@ -1,84 +1,182 @@
|
|
|
1
|
-
**中文** | [English](./README-en.md)
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
<a href="https://github.com/MengXi-Studio/vite-plugin">
|
|
5
|
-
<img alt="梦曦工作室 Logo" width="215" src="https://github.com/MengXi-Studio/vite-plugin/blob/master/packages/docs/src/public/logo.svg">
|
|
6
|
-
</a>
|
|
7
|
-
<br>
|
|
8
|
-
<h1>@meng-xi/vite-plugin</h1>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-

|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://github.com/MengXi-Studio/vite-plugin">
|
|
5
|
+
<img alt="梦曦工作室 Logo" width="215" src="https://github.com/MengXi-Studio/vite-plugin/blob/master/packages/docs/src/public/logo.svg">
|
|
6
|
+
</a>
|
|
7
|
+
<br>
|
|
8
|
+
<h1>@meng-xi/vite-plugin</h1>
|
|
9
|
+
<p>一个为 Vite 提供实用插件的工具包,同时也是一个完整的插件开发框架</p>
|
|
10
|
+
|
|
11
|
+
[](LICENSE) [](https://www.npmjs.com/package/@meng-xi/vite-plugin)
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## 特性
|
|
17
|
+
|
|
18
|
+
- **开箱即用** - 提供文件复制、路由生成、版本管理、图标注入等实用插件
|
|
19
|
+
- **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义插件
|
|
20
|
+
- **类型安全** - 完整的 TypeScript 类型定义,配置验证器确保参数正确性
|
|
21
|
+
- **灵活配置** - 所有插件支持详细配置,满足多样化场景需求
|
|
22
|
+
|
|
23
|
+
## 文档
|
|
24
|
+
|
|
25
|
+
查看完整文档:[https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
|
|
26
|
+
|
|
27
|
+
## 安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# npm
|
|
31
|
+
npm install @meng-xi/vite-plugin -D
|
|
32
|
+
|
|
33
|
+
# yarn
|
|
34
|
+
yarn add @meng-xi/vite-plugin -D
|
|
35
|
+
|
|
36
|
+
# pnpm
|
|
37
|
+
pnpm add @meng-xi/vite-plugin -D
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 快速开始
|
|
41
|
+
|
|
42
|
+
### 使用内置插件
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { defineConfig } from 'vite'
|
|
46
|
+
import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
|
|
47
|
+
|
|
48
|
+
export default defineConfig({
|
|
49
|
+
plugins: [
|
|
50
|
+
// 复制文件
|
|
51
|
+
copyFile({
|
|
52
|
+
sourceDir: 'src/assets',
|
|
53
|
+
targetDir: 'dist/assets'
|
|
54
|
+
}),
|
|
55
|
+
|
|
56
|
+
// 生成路由配置(uni-app)
|
|
57
|
+
generateRouter({
|
|
58
|
+
pagesJsonPath: 'src/pages.json',
|
|
59
|
+
outputPath: 'src/router.config.ts'
|
|
60
|
+
}),
|
|
61
|
+
|
|
62
|
+
// 生成版本号
|
|
63
|
+
generateVersion({
|
|
64
|
+
format: 'datetime',
|
|
65
|
+
outputType: 'both'
|
|
66
|
+
}),
|
|
67
|
+
|
|
68
|
+
// 注入网站图标
|
|
69
|
+
injectIco({
|
|
70
|
+
base: '/assets'
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 开发自定义插件
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
|
|
80
|
+
import type { Plugin } from 'vite'
|
|
81
|
+
|
|
82
|
+
interface MyPluginOptions {
|
|
83
|
+
path: string
|
|
84
|
+
enabled?: boolean
|
|
85
|
+
verbose?: boolean
|
|
86
|
+
errorStrategy?: 'throw' | 'log' | 'ignore'
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class MyPlugin extends BasePlugin<MyPluginOptions> {
|
|
90
|
+
protected getDefaultOptions() {
|
|
91
|
+
return { path: './default' }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected validateOptions(): void {
|
|
95
|
+
this.validator.field('path').required().string().validate()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected getPluginName(): string {
|
|
99
|
+
return 'my-plugin'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
protected addPluginHooks(plugin: Plugin): void {
|
|
103
|
+
plugin.buildStart = () => {
|
|
104
|
+
this.logger.info(`Plugin started with path: ${this.options.path}`)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const myPlugin = createPluginFactory(MyPlugin)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 内置插件
|
|
113
|
+
|
|
114
|
+
### copyFile
|
|
115
|
+
|
|
116
|
+
在 Vite 构建完成后复制文件或目录到指定位置。
|
|
117
|
+
|
|
118
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
119
|
+
| ----------- | ------- | ------ | -------------------- |
|
|
120
|
+
| sourceDir | string | - | 源目录路径(必填) |
|
|
121
|
+
| targetDir | string | - | 目标目录路径(必填) |
|
|
122
|
+
| overwrite | boolean | true | 是否覆盖现有文件 |
|
|
123
|
+
| recursive | boolean | true | 是否递归复制子目录 |
|
|
124
|
+
| incremental | boolean | true | 是否启用增量复制 |
|
|
125
|
+
|
|
126
|
+
### generateRouter
|
|
127
|
+
|
|
128
|
+
根据 uni-app 项目的 `pages.json` 自动生成路由配置文件。
|
|
129
|
+
|
|
130
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
131
|
+
| -------------------- | ------------ | ---------------------- | ----------------------------- |
|
|
132
|
+
| pagesJsonPath | string | 'src/pages.json' | pages.json 文件路径 |
|
|
133
|
+
| outputPath | string | 'src/router.config.ts' | 输出文件路径 |
|
|
134
|
+
| outputFormat | 'ts' \| 'js' | 'ts' | 输出文件格式 |
|
|
135
|
+
| nameStrategy | string | 'camelCase' | 路由名称策略 |
|
|
136
|
+
| includeSubPackages | boolean | true | 是否包含子包路由 |
|
|
137
|
+
| watch | boolean | true | 是否监听变化自动重新生成 |
|
|
138
|
+
| metaMapping | object | - | 页面 style 字段到 meta 的映射 |
|
|
139
|
+
| preserveRouteChanges | boolean | true | 是否保留用户对 routes 的修改 |
|
|
140
|
+
|
|
141
|
+
### generateVersion
|
|
142
|
+
|
|
143
|
+
在 Vite 构建过程中自动生成版本号。
|
|
144
|
+
|
|
145
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
146
|
+
| ---------- | ------ | --------------------- | ---------------- |
|
|
147
|
+
| format | string | 'timestamp' | 版本格式 |
|
|
148
|
+
| outputType | string | 'file' | 输出类型 |
|
|
149
|
+
| outputFile | string | 'version.json' | 输出文件路径 |
|
|
150
|
+
| defineName | string | '\_\_APP_VERSION\_\_' | 注入的全局变量名 |
|
|
151
|
+
| prefix | string | - | 版本号前缀 |
|
|
152
|
+
| suffix | string | - | 版本号后缀 |
|
|
153
|
+
|
|
154
|
+
### injectIco
|
|
155
|
+
|
|
156
|
+
在 Vite 构建过程中将网站图标链接注入到 HTML 文件的 head 中。
|
|
157
|
+
|
|
158
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
159
|
+
| ----------- | ------ | ------ | --------------------------- |
|
|
160
|
+
| base | string | - | 图标文件的基础路径 |
|
|
161
|
+
| url | string | - | 图标的完整 URL |
|
|
162
|
+
| link | string | - | 自定义完整的 link 标签 HTML |
|
|
163
|
+
| icons | array | - | 自定义图标数组 |
|
|
164
|
+
| copyOptions | object | - | 图标文件复制配置 |
|
|
165
|
+
|
|
166
|
+
## 更新日志
|
|
167
|
+
|
|
168
|
+
查看 [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
|
|
169
|
+
|
|
170
|
+
## 贡献指南
|
|
171
|
+
|
|
172
|
+
欢迎贡献代码!请按以下步骤操作:
|
|
173
|
+
|
|
174
|
+
1. Fork 本项目
|
|
175
|
+
2. 创建功能分支:`git checkout -b feature/your-feature`
|
|
176
|
+
3. 提交变更:`git commit -m "feat: your feature description"`
|
|
177
|
+
4. 推送分支:`git push origin feature/your-feature`
|
|
178
|
+
5. 创建 Pull Request
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
[MIT](LICENSE)
|
package/dist/common/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const format=require("../shared/vite-plugin.BZsetDCm.cjs"),validation=require("../shared/vite-plugin.IGZeStMa.cjs");require("fs"),require("path"),require("crypto"),exports.checkSourceExists=format.checkSourceExists,exports.copySourceToTarget=format.copySourceToTarget,exports.ensureTargetDir=format.ensureTargetDir,exports.fileExists=format.fileExists,exports.formatDate=format.formatDate,exports.generateRandomHash=format.generateRandomHash,exports.getDateFormatParams=format.getDateFormatParams,exports.padNumber=format.padNumber,exports.parseTemplate=format.parseTemplate,exports.readDirRecursive=format.readDirRecursive,exports.readFileSync=format.readFileSync,exports.runWithConcurrency=format.runWithConcurrency,exports.shouldUpdateFile=format.shouldUpdateFile,exports.stripJsonComments=format.stripJsonComments,exports.toCamelCase=format.toCamelCase,exports.toPascalCase=format.toPascalCase,exports.writeFileContent=format.writeFileContent,exports.Validator=validation.Validator,exports.deepMerge=validation.deepMerge;
|