@halo-dev/ui-plugin-bundler-kit 2.21.0 → 2.21.2
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 +333 -0
- package/dist/index.d.ts +73 -8
- package/dist/index.js +218 -0
- package/package.json +17 -18
- package/src/constants/build.ts +4 -0
- package/src/constants/externals.ts +16 -0
- package/src/constants/halo-plugin.ts +3 -0
- package/src/index.ts +3 -0
- package/src/legacy.ts +69 -0
- package/src/rsbuild.ts +146 -0
- package/src/utils/halo-plugin.ts +11 -0
- package/src/vite.ts +85 -0
- package/tsconfig.json +18 -0
- package/tsdown.config.ts +10 -0
- package/dist/index.cjs +0 -3928
- package/dist/index.mjs +0 -3920
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# @halo-dev/ui-plugin-bundler-kit
|
|
2
|
+
|
|
3
|
+
A frontend build toolkit for Halo plugin development, supporting both Vite and Rsbuild build systems.
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
`@halo-dev/ui-plugin-bundler-kit` is a frontend build configuration toolkit specifically designed for Halo plugin development. It provides pre-configured build settings to help developers quickly set up and build frontend interfaces for Halo plugins.
|
|
8
|
+
|
|
9
|
+
### Key Features
|
|
10
|
+
|
|
11
|
+
- 🚀 **Ready to Use** - Provides pre-configured Vite and Rsbuild build settings
|
|
12
|
+
- 📦 **Multi-Build Tool Support** - Supports both Vite and Rsbuild
|
|
13
|
+
- 🔧 **Flexible Configuration** - Supports custom build configurations
|
|
14
|
+
- 🎯 **Halo Optimized** - External dependencies and global variables optimized for Halo plugin development
|
|
15
|
+
- 📁 **Smart Output** - Automatically selects output directory based on environment
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Using npm
|
|
21
|
+
npm install @halo-dev/ui-plugin-bundler-kit
|
|
22
|
+
|
|
23
|
+
# Using yarn
|
|
24
|
+
yarn add @halo-dev/ui-plugin-bundler-kit
|
|
25
|
+
|
|
26
|
+
# Using pnpm
|
|
27
|
+
pnpm add @halo-dev/ui-plugin-bundler-kit
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Additional Dependencies
|
|
31
|
+
|
|
32
|
+
**For Vite users**, you need to install Vite:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install vite
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**For Rsbuild users**, you need to install Rsbuild:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install @rsbuild/core
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### Vite Configuration
|
|
47
|
+
|
|
48
|
+
Create or update `vite.config.ts` file in your project root:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { viteConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
52
|
+
|
|
53
|
+
export default viteConfig({
|
|
54
|
+
vite: {
|
|
55
|
+
// Your custom Vite configuration
|
|
56
|
+
plugins: [
|
|
57
|
+
// Additional plugins (Vue plugin is already included)
|
|
58
|
+
],
|
|
59
|
+
// Other configurations...
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Note**: Vue plugin is pre-configured, no need to add it manually.
|
|
65
|
+
|
|
66
|
+
### Rsbuild Configuration
|
|
67
|
+
|
|
68
|
+
Create or update `rsbuild.config.ts` file in your project root:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { rsbuildConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
72
|
+
|
|
73
|
+
export default rsbuildConfig({
|
|
74
|
+
rsbuild: {
|
|
75
|
+
// Your custom Rsbuild configuration
|
|
76
|
+
plugins: [
|
|
77
|
+
// Additional plugins (Vue plugin is already included)
|
|
78
|
+
],
|
|
79
|
+
// Other configurations...
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
> **Note**: Vue plugin is pre-configured, no need to add it manually.
|
|
85
|
+
|
|
86
|
+
### Legacy Configuration (Deprecated)
|
|
87
|
+
|
|
88
|
+
> ⚠️ **Note**: The `HaloUIPluginBundlerKit` function is deprecated. Please use `viteConfig` or `rsbuildConfig` instead.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { HaloUIPluginBundlerKit } from "@halo-dev/ui-plugin-bundler-kit";
|
|
92
|
+
|
|
93
|
+
export default {
|
|
94
|
+
plugins: [
|
|
95
|
+
HaloUIPluginBundlerKit({
|
|
96
|
+
// Configuration options
|
|
97
|
+
}),
|
|
98
|
+
],
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration Options
|
|
103
|
+
|
|
104
|
+
### Vite Configuration Options
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
interface ViteUserConfig {
|
|
108
|
+
/**
|
|
109
|
+
* Halo plugin manifest file path
|
|
110
|
+
* @default "../src/main/resources/plugin.yaml"
|
|
111
|
+
*/
|
|
112
|
+
manifestPath?: string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Custom Vite configuration
|
|
116
|
+
*/
|
|
117
|
+
vite: UserConfig | UserConfigFnObject;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Rsbuild Configuration Options
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
interface RsBuildUserConfig {
|
|
125
|
+
/**
|
|
126
|
+
* Halo plugin manifest file path
|
|
127
|
+
* @default "../src/main/resources/plugin.yaml"
|
|
128
|
+
*/
|
|
129
|
+
manifestPath?: string;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Custom Rsbuild configuration
|
|
133
|
+
*/
|
|
134
|
+
rsbuild: RsbuildConfig | ((env: ConfigParams) => RsbuildConfig);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Advanced Configuration Examples
|
|
139
|
+
|
|
140
|
+
### Adding Path Aliases (Vite)
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { viteConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
144
|
+
import path from "path";
|
|
145
|
+
|
|
146
|
+
export default viteConfig({
|
|
147
|
+
vite: {
|
|
148
|
+
resolve: {
|
|
149
|
+
alias: {
|
|
150
|
+
"@": path.resolve(__dirname, "src"),
|
|
151
|
+
"@components": path.resolve(__dirname, "src/components"),
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Adding Path Aliases (Rsbuild)
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { rsbuildConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
162
|
+
|
|
163
|
+
export default rsbuildConfig({
|
|
164
|
+
rsbuild: {
|
|
165
|
+
source: {
|
|
166
|
+
alias: {
|
|
167
|
+
"@": "./src",
|
|
168
|
+
"@components": "./src/components",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Adding Additional Vite Plugins
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import { viteConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
179
|
+
import { defineConfig } from "vite";
|
|
180
|
+
import UnoCSS from "unocss/vite";
|
|
181
|
+
|
|
182
|
+
export default viteConfig({
|
|
183
|
+
vite: {
|
|
184
|
+
plugins: [
|
|
185
|
+
UnoCSS(), // Add UnoCSS plugin
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Adding Additional Rsbuild Plugins
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { rsbuildConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
195
|
+
import { pluginSass } from "@rsbuild/plugin-sass";
|
|
196
|
+
|
|
197
|
+
export default rsbuildConfig({
|
|
198
|
+
rsbuild: {
|
|
199
|
+
plugins: [
|
|
200
|
+
pluginSass(), // Add Sass plugin
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Custom Plugin Manifest Path
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { viteConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
210
|
+
|
|
211
|
+
export default viteConfig({
|
|
212
|
+
manifestPath: "application/src/main/resources/plugin.yaml", // Custom manifest file path
|
|
213
|
+
vite: {
|
|
214
|
+
// Other configurations...
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Development Scripts
|
|
220
|
+
|
|
221
|
+
Recommended scripts to add to your `package.json`:
|
|
222
|
+
|
|
223
|
+
```json
|
|
224
|
+
{
|
|
225
|
+
"scripts": {
|
|
226
|
+
"dev": "vite dev --mode=development --watch",
|
|
227
|
+
"build": "vite build"
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
For Rsbuild:
|
|
233
|
+
|
|
234
|
+
```json
|
|
235
|
+
{
|
|
236
|
+
"scripts": {
|
|
237
|
+
"dev": "rsbuild dev --env-mode=development --watch",
|
|
238
|
+
"build": "rsbuild build"
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Build Output
|
|
244
|
+
|
|
245
|
+
> Relative to the root directory of the Halo plugin project
|
|
246
|
+
|
|
247
|
+
- **Development**: `build/resources/main/console`
|
|
248
|
+
- **Production**: `ui/build/dist`
|
|
249
|
+
|
|
250
|
+
> **Note**: The production build output directory of `HaloUIPluginBundlerKit` is still `src/main/resources/console` to ensure compatibility.
|
|
251
|
+
|
|
252
|
+
## Requirements
|
|
253
|
+
|
|
254
|
+
- **Node.js**: ^18.0.0 || >=20.0.0
|
|
255
|
+
- **Peer Dependencies**:
|
|
256
|
+
- `@rsbuild/core`: ^1.0.0 (when using Rsbuild)
|
|
257
|
+
- `@rsbuild/plugin-vue`: ^1.0.0 (when using Rsbuild)
|
|
258
|
+
- `@vitejs/plugin-vue`: ^4.0.0 || ^5.0.0 (when using Vite)
|
|
259
|
+
- `vite`: ^4.0.0 || ^5.0.0 || ^6.0.0 (when using Vite)
|
|
260
|
+
|
|
261
|
+
## Vite vs Rsbuild
|
|
262
|
+
|
|
263
|
+
Both Vite and Rsbuild are excellent build tools, but they have different strengths depending on your use case:
|
|
264
|
+
|
|
265
|
+
### When to Use Rsbuild
|
|
266
|
+
|
|
267
|
+
**Recommended for large-scale plugins**
|
|
268
|
+
|
|
269
|
+
- ✅ **Code Splitting Support** - Rsbuild provides excellent support for code splitting and lazy loading
|
|
270
|
+
- ✅ **Better Performance** - Generally faster build times and smaller bundle sizes for complex applications
|
|
271
|
+
- ✅ **Dynamic Imports** - Perfect for plugins with heavy frontend components
|
|
272
|
+
|
|
273
|
+
**Example with dynamic imports:**
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { definePlugin } from "@halo-dev/console-shared";
|
|
277
|
+
import { defineAsyncComponent } from "vue";
|
|
278
|
+
import { VLoading } from "@halo-dev/components";
|
|
279
|
+
|
|
280
|
+
export default definePlugin({
|
|
281
|
+
routes: [
|
|
282
|
+
{
|
|
283
|
+
parentName: "Root",
|
|
284
|
+
route: {
|
|
285
|
+
path: "demo",
|
|
286
|
+
name: "DemoPage",
|
|
287
|
+
// Lazy load heavy components
|
|
288
|
+
component: defineAsyncComponent({
|
|
289
|
+
loader: () => import("./views/DemoPage.vue"),
|
|
290
|
+
loadingComponent: VLoading,
|
|
291
|
+
}),
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
extensionPoints: {},
|
|
296
|
+
});
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### When to Use Vite
|
|
300
|
+
|
|
301
|
+
**Recommended for simple to medium-scale plugins**
|
|
302
|
+
|
|
303
|
+
- ✅ **Vue Ecosystem Friendly** - Better integration with Vue ecosystem tools and plugins
|
|
304
|
+
- ✅ **Rich Plugin Ecosystem** - Extensive collection of Vite plugins available
|
|
305
|
+
- ✅ **Simple Configuration** - Easier to configure for straightforward use cases
|
|
306
|
+
|
|
307
|
+
### Summary
|
|
308
|
+
|
|
309
|
+
| Feature | Vite | Rsbuild |
|
|
310
|
+
| ----------------- | ------------ | ------------ |
|
|
311
|
+
| Code Splitting | ❌ Limited | ✅ Excellent |
|
|
312
|
+
| Vue Ecosystem | ✅ Excellent | ✅ Good |
|
|
313
|
+
| Build Performance | ✅ Good | ✅ Excellent |
|
|
314
|
+
| Dev Experience | ✅ Excellent | ✅ Excellent |
|
|
315
|
+
| Plugin Ecosystem | ✅ Rich | ✅ Growing |
|
|
316
|
+
| Configuration | ✅ Simple | ⚖️ Moderate |
|
|
317
|
+
|
|
318
|
+
**Recommendation**: Use **Rsbuild** for complex plugins with large frontend codebases, and **Vite** for simpler plugins or when you need extensive Vue ecosystem integration.
|
|
319
|
+
|
|
320
|
+
## License
|
|
321
|
+
|
|
322
|
+
GPL-3.0
|
|
323
|
+
|
|
324
|
+
## Contributing
|
|
325
|
+
|
|
326
|
+
Issues and Pull Requests are welcome! Please check our [Contributing Guide](https://github.com/halo-dev/halo/blob/main/CONTRIBUTING.md) for more information.
|
|
327
|
+
|
|
328
|
+
## Related Links
|
|
329
|
+
|
|
330
|
+
- [Halo Website](https://www.halo.run/)
|
|
331
|
+
- [Halo Documentation](https://docs.halo.run/)
|
|
332
|
+
- [GitHub Repository](https://github.com/halo-dev/halo)
|
|
333
|
+
- [Plugin Development Guide](https://docs.halo.run/category/ui)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,77 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConfigParams, RsbuildConfig } from "@rsbuild/core";
|
|
2
|
+
import { Plugin, UserConfig, UserConfigFnObject } from "vite";
|
|
2
3
|
|
|
4
|
+
//#region src/legacy.d.ts
|
|
3
5
|
interface HaloUIPluginBundlerKitOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
outDir?: string | {
|
|
7
|
+
dev: string;
|
|
8
|
+
prod: string;
|
|
9
|
+
};
|
|
10
|
+
manifestPath?: string;
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `viteConfig` or `rsbuildConfig` instead.
|
|
14
|
+
*/
|
|
10
15
|
declare function HaloUIPluginBundlerKit(options?: HaloUIPluginBundlerKitOptions): Plugin;
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/rsbuild.d.ts
|
|
18
|
+
interface RsBuildUserConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Halo plugin manifest path.
|
|
21
|
+
*
|
|
22
|
+
* @default "../src/main/resources/plugin.yaml"
|
|
23
|
+
*/
|
|
24
|
+
manifestPath?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Custom Rsbuild config.
|
|
27
|
+
*/
|
|
28
|
+
rsbuild: RsbuildConfig | ((env: ConfigParams) => RsbuildConfig);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Rsbuild config for Halo UI Plugin.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { rsbuildConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
36
|
+
*
|
|
37
|
+
* export default rsbuildConfig({
|
|
38
|
+
* rsbuild: {
|
|
39
|
+
* // your custom rsbuild config
|
|
40
|
+
* },
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
* @param config
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
declare function rsbuildConfig(config?: RsBuildUserConfig): (env: ConfigParams) => RsbuildConfig;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/vite.d.ts
|
|
49
|
+
interface ViteUserConfig {
|
|
50
|
+
/**
|
|
51
|
+
* Halo plugin manifest path.
|
|
52
|
+
*
|
|
53
|
+
* @default "../src/main/resources/plugin.yaml"
|
|
54
|
+
*/
|
|
55
|
+
manifestPath?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Custom Vite config.
|
|
58
|
+
*/
|
|
59
|
+
vite: UserConfig | UserConfigFnObject;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Vite config for Halo UI Plugin.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { viteConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
67
|
+
*
|
|
68
|
+
* export default viteConfig({
|
|
69
|
+
* vite: {
|
|
70
|
+
* // your custom vite config
|
|
71
|
+
* },
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function viteConfig(config?: ViteUserConfig): UserConfigFnObject;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { HaloUIPluginBundlerKit, rsbuildConfig, viteConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import yaml from "js-yaml";
|
|
3
|
+
import { defineConfig, mergeRsbuildConfig } from "@rsbuild/core";
|
|
4
|
+
import { pluginVue } from "@rsbuild/plugin-vue";
|
|
5
|
+
import Vue from "@vitejs/plugin-vue";
|
|
6
|
+
import { defineConfig as defineConfig$1, mergeConfig } from "vite";
|
|
7
|
+
|
|
8
|
+
//#region src/constants/build.ts
|
|
9
|
+
const DEFAULT_OUT_DIR_DEV = "../build/resources/main/console";
|
|
10
|
+
const DEFAULT_OUT_DIR_PROD = "./build/dist";
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/constants/externals.ts
|
|
14
|
+
const GLOBALS = {
|
|
15
|
+
vue: "Vue",
|
|
16
|
+
"vue-router": "VueRouter",
|
|
17
|
+
"@vueuse/core": "VueUse",
|
|
18
|
+
"@vueuse/components": "VueUse",
|
|
19
|
+
"@vueuse/router": "VueUse",
|
|
20
|
+
"@halo-dev/console-shared": "HaloConsoleShared",
|
|
21
|
+
"@halo-dev/components": "HaloComponents",
|
|
22
|
+
"@halo-dev/api-client": "HaloApiClient",
|
|
23
|
+
"@halo-dev/richtext-editor": "RichTextEditor",
|
|
24
|
+
axios: "axios"
|
|
25
|
+
};
|
|
26
|
+
const EXTERNALS = Object.keys(GLOBALS);
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/constants/halo-plugin.ts
|
|
30
|
+
const DEFAULT_MANIFEST_PATH = "../src/main/resources/plugin.yaml";
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/utils/halo-plugin.ts
|
|
34
|
+
function getHaloPluginManifest(manifestPath) {
|
|
35
|
+
const manifest = yaml.load(fs.readFileSync(manifestPath, "utf8"));
|
|
36
|
+
return manifest;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/legacy.ts
|
|
41
|
+
const LEGACY_OUT_DIR_PROD = "../src/main/resources/console";
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Use `viteConfig` or `rsbuildConfig` instead.
|
|
44
|
+
*/
|
|
45
|
+
function HaloUIPluginBundlerKit(options = {}) {
|
|
46
|
+
return {
|
|
47
|
+
name: "halo-ui-plugin-bundler-kit",
|
|
48
|
+
config(config, env) {
|
|
49
|
+
const isProduction = env.mode === "production";
|
|
50
|
+
let outDir = isProduction ? LEGACY_OUT_DIR_PROD : DEFAULT_OUT_DIR_DEV;
|
|
51
|
+
if (options.outDir) if (typeof options.outDir === "string") outDir = options.outDir;
|
|
52
|
+
else outDir = isProduction ? options.outDir.prod : options.outDir.dev;
|
|
53
|
+
const manifestPath = options.manifestPath || DEFAULT_MANIFEST_PATH;
|
|
54
|
+
const manifest = getHaloPluginManifest(manifestPath);
|
|
55
|
+
return {
|
|
56
|
+
...config,
|
|
57
|
+
define: { "process.env": process.env },
|
|
58
|
+
build: {
|
|
59
|
+
outDir,
|
|
60
|
+
emptyOutDir: true,
|
|
61
|
+
lib: {
|
|
62
|
+
entry: "src/index.ts",
|
|
63
|
+
name: manifest.metadata.name,
|
|
64
|
+
formats: ["iife"],
|
|
65
|
+
fileName: () => "main.js"
|
|
66
|
+
},
|
|
67
|
+
rollupOptions: {
|
|
68
|
+
external: EXTERNALS,
|
|
69
|
+
output: {
|
|
70
|
+
globals: GLOBALS,
|
|
71
|
+
extend: true
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/rsbuild.ts
|
|
82
|
+
function createRsbuildPresetsConfig(manifestPath) {
|
|
83
|
+
const manifest = getHaloPluginManifest(manifestPath);
|
|
84
|
+
return defineConfig(({ envMode }) => {
|
|
85
|
+
const isProduction = envMode === "production";
|
|
86
|
+
const outDir = isProduction ? DEFAULT_OUT_DIR_PROD : DEFAULT_OUT_DIR_DEV;
|
|
87
|
+
return {
|
|
88
|
+
mode: envMode || "production",
|
|
89
|
+
plugins: [pluginVue()],
|
|
90
|
+
source: { entry: { main: "./src/index.ts" } },
|
|
91
|
+
dev: { hmr: false },
|
|
92
|
+
performance: { chunkSplit: { strategy: "custom" } },
|
|
93
|
+
tools: {
|
|
94
|
+
rspack: {
|
|
95
|
+
optimization: {
|
|
96
|
+
splitChunks: { chunks: "async" },
|
|
97
|
+
moduleIds: "named"
|
|
98
|
+
},
|
|
99
|
+
experiments: { rspackFuture: { bundlerInfo: { force: false } } },
|
|
100
|
+
module: { parser: { javascript: { importMeta: false } } },
|
|
101
|
+
output: {
|
|
102
|
+
publicPath: `/plugins/${manifest.metadata.name}/assets/console/`,
|
|
103
|
+
library: {
|
|
104
|
+
type: "window",
|
|
105
|
+
export: "default",
|
|
106
|
+
name: manifest.metadata.name
|
|
107
|
+
},
|
|
108
|
+
globalObject: "window",
|
|
109
|
+
iife: true
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
htmlPlugin: false
|
|
113
|
+
},
|
|
114
|
+
output: {
|
|
115
|
+
distPath: {
|
|
116
|
+
root: outDir,
|
|
117
|
+
js: "",
|
|
118
|
+
css: "",
|
|
119
|
+
jsAsync: "chunks",
|
|
120
|
+
cssAsync: "chunks"
|
|
121
|
+
},
|
|
122
|
+
cleanDistPath: true,
|
|
123
|
+
filename: {
|
|
124
|
+
css: (pathData) => {
|
|
125
|
+
if (pathData.chunk?.name === "main") return "style.css";
|
|
126
|
+
return "[name].[contenthash:8].css";
|
|
127
|
+
},
|
|
128
|
+
js: (pathData) => {
|
|
129
|
+
if (pathData.chunk?.name === "main") return "main.js";
|
|
130
|
+
return "[name].[contenthash:8].js";
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
externals: GLOBALS
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Rsbuild config for Halo UI Plugin.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { rsbuildConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
144
|
+
*
|
|
145
|
+
* export default rsbuildConfig({
|
|
146
|
+
* rsbuild: {
|
|
147
|
+
* // your custom rsbuild config
|
|
148
|
+
* },
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
* @param config
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
function rsbuildConfig(config) {
|
|
155
|
+
const presetsConfigFn = createRsbuildPresetsConfig(config?.manifestPath || DEFAULT_MANIFEST_PATH);
|
|
156
|
+
return defineConfig((env) => {
|
|
157
|
+
const presetsConfig = presetsConfigFn(env);
|
|
158
|
+
const userConfig = typeof config?.rsbuild === "function" ? config.rsbuild(env) : config?.rsbuild || {};
|
|
159
|
+
return mergeRsbuildConfig(presetsConfig, userConfig);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/vite.ts
|
|
165
|
+
function createVitePresetsConfig(manifestPath) {
|
|
166
|
+
const manifest = getHaloPluginManifest(manifestPath);
|
|
167
|
+
return defineConfig$1(({ mode }) => {
|
|
168
|
+
const isProduction = mode === "production";
|
|
169
|
+
return {
|
|
170
|
+
mode: mode || "production",
|
|
171
|
+
plugins: [Vue()],
|
|
172
|
+
define: { "process.env.NODE_ENV": "'production'" },
|
|
173
|
+
build: {
|
|
174
|
+
outDir: isProduction ? DEFAULT_OUT_DIR_PROD : DEFAULT_OUT_DIR_DEV,
|
|
175
|
+
emptyOutDir: true,
|
|
176
|
+
lib: {
|
|
177
|
+
entry: "src/index.ts",
|
|
178
|
+
name: manifest.metadata.name,
|
|
179
|
+
formats: ["iife"],
|
|
180
|
+
fileName: () => "main.js",
|
|
181
|
+
cssFileName: "style"
|
|
182
|
+
},
|
|
183
|
+
rollupOptions: {
|
|
184
|
+
external: EXTERNALS,
|
|
185
|
+
output: {
|
|
186
|
+
globals: GLOBALS,
|
|
187
|
+
extend: true
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Vite config for Halo UI Plugin.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* import { viteConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
200
|
+
*
|
|
201
|
+
* export default viteConfig({
|
|
202
|
+
* vite: {
|
|
203
|
+
* // your custom vite config
|
|
204
|
+
* },
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
function viteConfig(config) {
|
|
209
|
+
const presetsConfigFn = createVitePresetsConfig(config?.manifestPath || DEFAULT_MANIFEST_PATH);
|
|
210
|
+
return defineConfig$1((env) => {
|
|
211
|
+
const presetsConfig = presetsConfigFn(env);
|
|
212
|
+
const userConfig = typeof config?.vite === "function" ? config.vite(env) : config?.vite || {};
|
|
213
|
+
return mergeConfig(presetsConfig, userConfig);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//#endregion
|
|
218
|
+
export { HaloUIPluginBundlerKit, rsbuildConfig, viteConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@halo-dev/ui-plugin-bundler-kit",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.2",
|
|
4
4
|
"homepage": "https://github.com/halo-dev/halo/tree/main/ui/packages/ui-plugin-bundler-kit#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/halo-dev/halo/issues"
|
|
@@ -12,33 +12,32 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "GPL-3.0",
|
|
14
14
|
"author": "@halo-dev",
|
|
15
|
+
"type": "module",
|
|
15
16
|
"exports": {
|
|
16
|
-
".":
|
|
17
|
-
|
|
18
|
-
"require": "./dist/index.cjs",
|
|
19
|
-
"types": "./dist/index.d.ts"
|
|
20
|
-
}
|
|
17
|
+
".": "./dist/index.js",
|
|
18
|
+
"./package.json": "./package.json"
|
|
21
19
|
},
|
|
22
|
-
"main": "./dist/index.
|
|
23
|
-
"module": "./dist/index.
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.js",
|
|
24
22
|
"types": "./dist/index.d.ts",
|
|
25
|
-
"
|
|
26
|
-
"dist"
|
|
27
|
-
],
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/js-yaml": "^4.0.9",
|
|
23
|
+
"dependencies": {
|
|
30
24
|
"js-yaml": "^4.1.0",
|
|
31
|
-
"
|
|
32
|
-
|
|
25
|
+
"@halo-dev/api-client": "2.21.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/js-yaml": "^4.0.9"
|
|
33
29
|
},
|
|
34
30
|
"peerDependencies": {
|
|
35
|
-
"
|
|
31
|
+
"@rsbuild/core": "^1.0.0",
|
|
32
|
+
"@rsbuild/plugin-vue": "^1.0.0",
|
|
33
|
+
"@vitejs/plugin-vue": "^5.0.0 || ^6.0.0",
|
|
34
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
36
35
|
},
|
|
37
36
|
"engines": {
|
|
38
37
|
"node": "^18.0.0 || >=20.0.0"
|
|
39
38
|
},
|
|
40
39
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"dev": "
|
|
40
|
+
"build": "tsdown",
|
|
41
|
+
"dev": "tsdown --watch"
|
|
43
42
|
}
|
|
44
43
|
}
|