@pubinfo/vite 2.0.0-beta.9 → 2.0.0-rc.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/dist/index.d.ts CHANGED
@@ -1,28 +1,63 @@
1
- import * as _pubinfo_unplugin_openapi from '@pubinfo/unplugin-openapi';
2
- import { Options } from '@pubinfo/unplugin-openapi';
3
- import { UserConfig, UserConfigFnObject } from 'vite';
4
- export * from 'vite';
1
+ import { UserConfig, UserConfigFnObject } from "rolldown-vite";
2
+ import * as _pubinfo_unplugin_openapi0 from "@pubinfo/unplugin-openapi";
3
+ import { Options } from "@pubinfo/unplugin-openapi";
4
+ export * from "rolldown-vite";
5
+ export * from "vite-plugin-fake-server/client";
5
6
 
7
+ //#region src/plugins/lib-resolver.d.ts
8
+ type GlobInput = string;
9
+ interface ModuleEntries {
10
+ /**
11
+ * 图标文件
12
+ * @default "src/assets/icons/**\/*"
13
+ */
14
+ icons?: GlobInput;
15
+ /**
16
+ * 布局文件
17
+ * @default "src/layouts/**\/*"
18
+ */
19
+ layouts?: GlobInput;
20
+ /**
21
+ * 页面文件
22
+ * @default "src/pages/**\/*"
23
+ */
24
+ pages?: GlobInput;
25
+ }
26
+ interface ResolverPluginOptions {
27
+ /** 入口配置 */
28
+ entries: ModuleEntries;
29
+ /** 启用缓存优化 */
30
+ cache?: boolean;
31
+ /** 最大缓存大小 */
32
+ maxCacheSize?: number;
33
+ }
34
+ //#endregion
35
+ //#region src/interface.d.ts
6
36
  interface PubinfoConfig {
7
- /** `vite` */
8
- vite?: UserConfig | UserConfigFnObject;
9
- /** `@pubinfo/unplugin-openapi` */
10
- openapi?: Options;
37
+ /** `vite` */
38
+ vite?: UserConfig | UserConfigFnObject;
39
+ /** `@pubinfo/unplugin-openapi` */
40
+ openapi?: Options;
41
+ /** `resolver` */
42
+ resolver?: ResolverPluginOptions;
11
43
  }
12
-
44
+ //#endregion
45
+ //#region src/config/index.d.ts
13
46
  /**
14
47
  * 构建应用配置
15
48
  */
16
49
  declare function definePubinfoConfig(config: PubinfoConfig): {
17
- vite: UserConfigFnObject;
18
- openapi?: _pubinfo_unplugin_openapi.Options;
50
+ vite: UserConfigFnObject;
51
+ openapi?: _pubinfo_unplugin_openapi0.Options;
52
+ resolver?: ResolverPluginOptions;
19
53
  };
20
54
  /**
21
55
  * 构建模块配置
22
56
  */
23
57
  declare function defineModuleConfig(config: PubinfoConfig): {
24
- vite: UserConfigFnObject;
25
- openapi?: _pubinfo_unplugin_openapi.Options;
58
+ vite: UserConfigFnObject;
59
+ openapi?: _pubinfo_unplugin_openapi0.Options;
60
+ resolver?: ResolverPluginOptions;
26
61
  };
27
-
28
- export { type PubinfoConfig, defineModuleConfig, definePubinfoConfig };
62
+ //#endregion
63
+ export { PubinfoConfig, ResolverPluginOptions, defineModuleConfig, definePubinfoConfig };
package/dist/index.js ADDED
@@ -0,0 +1,496 @@
1
+ import { createRequire } from "node:module";
2
+ import { defineConfig, loadEnv, mergeConfig } from "rolldown-vite";
3
+ import { cwd } from "node:process";
4
+ import chalk from "chalk";
5
+ import consola from "consola";
6
+ import { join, posix, relative, resolve } from "node:path";
7
+ import vue from "@vitejs/plugin-vue";
8
+ import vueJsx from "@vitejs/plugin-vue-jsx";
9
+ import autoImport from "unplugin-auto-import/vite";
10
+ import IconsResolver from "unplugin-icons/resolver";
11
+ import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
12
+ import components from "unplugin-vue-components/vite";
13
+ import compression from "vite-plugin-compression";
14
+ import dts from "vite-plugin-dts";
15
+ import Icons from "unplugin-icons/vite";
16
+ import boxen from "boxen";
17
+ import { libInjectCss } from "vite-plugin-lib-inject-css";
18
+ import VueDevTools from "vite-plugin-vue-devtools";
19
+ import vueLegacy from "@vitejs/plugin-legacy";
20
+ import { createHash } from "node:crypto";
21
+ import { existsSync, statSync } from "node:fs";
22
+ import fg from "fast-glob";
23
+ import { merge } from "lodash-es";
24
+ import { vitePluginFakeServer } from "vite-plugin-fake-server";
25
+ import OpenAPI from "@pubinfo/unplugin-openapi/vite";
26
+ import Unocss from "unocss/vite";
27
+
28
+ export * from "rolldown-vite"
29
+
30
+ export * from "vite-plugin-fake-server/client"
31
+
32
+ //#region src/helper/alias.ts
33
+ function alias(root) {
34
+ const resolvePath = (name) => join(root, name);
35
+ const resolveDeps = (name, path) => join(createRequire(import.meta.url).resolve(name), path);
36
+ return {
37
+ "@": resolvePath("src"),
38
+ "#": resolvePath("types"),
39
+ "vue": resolveDeps("vue", "../"),
40
+ "vue-router": resolveDeps("vue-router", "../"),
41
+ "pinia": resolveDeps("pinia", "../"),
42
+ "unocss": resolveDeps("unocss", "../")
43
+ };
44
+ }
45
+
46
+ //#endregion
47
+ //#region src/helper/index.ts
48
+ function getServerProxy(env, isProxy) {
49
+ if (!isProxy) return {};
50
+ const targetPrefix = "VITE_APP_API_";
51
+ const proxyKey = Object.keys(env).filter((key) => key.startsWith(targetPrefix));
52
+ const serverProxy = {};
53
+ for (const envKey of proxyKey) {
54
+ const url = env[envKey];
55
+ const { pathname } = new URL(url);
56
+ const pk = `${pathname}/proxy`;
57
+ if (pk in serverProxy) consola.error(`The proxy key ${chalk.bold.redBright(envKey)} ➜ ${chalk.bold.yellowBright(url)} already exists`);
58
+ else serverProxy[pk] = {
59
+ target: url,
60
+ changeOrigin: true,
61
+ rewrite: (path) => path.replace(pk, ""),
62
+ secure: false
63
+ };
64
+ }
65
+ return serverProxy;
66
+ }
67
+
68
+ //#endregion
69
+ //#region src/plugins/auto-import.ts
70
+ function createAutoImport() {
71
+ return autoImport({
72
+ imports: [
73
+ "vue",
74
+ "vue-router",
75
+ "pinia",
76
+ { pubinfo: ["useAuth"] }
77
+ ],
78
+ ignore: ["h"],
79
+ dts: "./.pubinfo/auto-imports.d.ts",
80
+ resolvers: [AntDesignVueResolver(), IconsResolver({ prefix: "i" })]
81
+ });
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/plugins/components.ts
86
+ function createComponents() {
87
+ return components({
88
+ dirs: ["src/components"],
89
+ directives: true,
90
+ include: [
91
+ /\.vue$/,
92
+ /\.vue\?vue/,
93
+ /\.tsx$/
94
+ ],
95
+ resolvers: [
96
+ IconsResolver(),
97
+ AntDesignVueResolver({
98
+ resolveIcons: true,
99
+ importStyle: false
100
+ }),
101
+ {
102
+ type: "component",
103
+ resolve(name) {
104
+ const components$1 = [
105
+ "PubinfoApp",
106
+ "PubinfoProvider",
107
+ "PubinfoIcon"
108
+ ];
109
+ if (components$1.includes(name)) return {
110
+ name,
111
+ from: "pubinfo"
112
+ };
113
+ }
114
+ }
115
+ ],
116
+ dts: "./.pubinfo/components.d.ts"
117
+ });
118
+ }
119
+
120
+ //#endregion
121
+ //#region src/plugins/compression.ts
122
+ function createCompression(env) {
123
+ const { VITE_BUILD_COMPRESS } = env;
124
+ const compressList = VITE_BUILD_COMPRESS?.split(",") ?? [];
125
+ const plugin = [];
126
+ if (compressList.includes("gzip")) plugin.push(compression({
127
+ ext: ".gz",
128
+ deleteOriginFile: false
129
+ }));
130
+ if (compressList.includes("brotli")) plugin.push(compression({
131
+ ext: ".br",
132
+ algorithm: "brotliCompress",
133
+ deleteOriginFile: false
134
+ }));
135
+ return plugin;
136
+ }
137
+
138
+ //#endregion
139
+ //#region src/plugins/dts.ts
140
+ function createDTS() {
141
+ return dts({
142
+ clearPureImport: false,
143
+ exclude: ["tests/**/*"]
144
+ });
145
+ }
146
+
147
+ //#endregion
148
+ //#region src/plugins/icon.ts
149
+ function createIcons() {
150
+ return Icons({ autoInstall: false });
151
+ }
152
+
153
+ //#endregion
154
+ //#region src/plugins/info.ts
155
+ var Ctx = class {
156
+ options;
157
+ setOptions(options) {
158
+ this.options = options;
159
+ }
160
+ async createInfo() {
161
+ console.log(boxen(`\
162
+ 欢迎使用${chalk.bold.greenBright(" 技术底座管理系统 ")}\n
163
+ ${chalk.green("使用文档地址")} ${chalk.green("➜")} https://134.108.39.195:9090/docs`, {
164
+ padding: 1,
165
+ margin: 1,
166
+ align: "center",
167
+ borderColor: "yellowBright",
168
+ borderStyle: "round"
169
+ }));
170
+ }
171
+ };
172
+ const ctx = new Ctx();
173
+ function appInfo() {
174
+ return {
175
+ name: "appInfo",
176
+ apply: "serve",
177
+ enforce: "pre",
178
+ configResolved(configuration) {
179
+ const root = configuration.root;
180
+ ctx.setOptions({ root });
181
+ },
182
+ async buildStart() {
183
+ ctx.createInfo();
184
+ },
185
+ configureServer(server) {
186
+ const _printUrls = server.printUrls;
187
+ server.printUrls = () => {
188
+ console.log(` ${chalk.green("➜")} ${chalk.bold.bgBlueBright(` PUBINFO `)}${chalk.bold.bgYellowBright(` 前端基础框架 `)}`);
189
+ _printUrls();
190
+ };
191
+ }
192
+ };
193
+ }
194
+
195
+ //#endregion
196
+ //#region src/plugins/inject-css.ts
197
+ function createInjectCSS() {
198
+ return libInjectCss();
199
+ }
200
+
201
+ //#endregion
202
+ //#region src/plugins/inspector.ts
203
+ function createInspector(env) {
204
+ const { VITE_APP_INSPECTOR } = env;
205
+ if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") return VueDevTools();
206
+ else return null;
207
+ }
208
+
209
+ //#endregion
210
+ //#region src/plugins/legacy.ts
211
+ function createLegacy(env) {
212
+ if (env.VITE_BUILD_LEGACY !== "true") return false;
213
+ return vueLegacy({
214
+ modernPolyfills: ["es.array.at", "es.array.find-last"],
215
+ additionalLegacyPolyfills: ["abort-controller/polyfill"]
216
+ });
217
+ }
218
+
219
+ //#endregion
220
+ //#region src/plugins/lib-resolver.ts
221
+ function getPatternBase(pattern) {
222
+ const parts = pattern.split("/");
223
+ const baseParts = [];
224
+ for (const part of parts) {
225
+ if (part.includes("*")) break;
226
+ baseParts.push(part);
227
+ }
228
+ return baseParts.join("/");
229
+ }
230
+ function normalizePath(path) {
231
+ return posix.normalize(path.replace(/\\/g, "/"));
232
+ }
233
+ function libResolverPlugin(options) {
234
+ const virtualModuleId = "virtual:pubinfo-resolver";
235
+ const resolvedId = `\0${virtualModuleId}`;
236
+ const enableCache = options.cache ?? true;
237
+ const maxCacheSize = options.maxCacheSize ?? 50;
238
+ const cache = /* @__PURE__ */ new Map();
239
+ return {
240
+ name: "vite-plugin-lib-resolver",
241
+ enforce: "pre",
242
+ buildStart() {
243
+ if (!enableCache) cache.clear();
244
+ },
245
+ async resolveId(id) {
246
+ return id === virtualModuleId ? resolvedId : null;
247
+ },
248
+ async load(id) {
249
+ if (id !== resolvedId) return null;
250
+ const configHash = createHash("md5").update(JSON.stringify(options.entries)).digest("hex");
251
+ if (enableCache && cache.has(configHash)) {
252
+ const cached = cache.get(configHash);
253
+ const hasChanges = await checkForFileChanges(options.entries, cached.fileHashes);
254
+ if (!hasChanges) return cached.content;
255
+ }
256
+ const moduleResults = await Promise.all(Object.entries(options.entries).map(async ([key, pattern]) => {
257
+ try {
258
+ const files = await fg(pattern, { absolute: true });
259
+ if (files.length === 0) return {
260
+ key,
261
+ content: `"${key}": {}`,
262
+ files: []
263
+ };
264
+ const base = getPatternBase(pattern);
265
+ const imports = files.map((file) => {
266
+ const absPath = normalizePath(file);
267
+ const relToBase = normalizePath(relative(resolve(base), file));
268
+ const relPath = posix.join(base, relToBase);
269
+ return `"${relPath}": () => import("${absPath}")`;
270
+ }).join(",\n");
271
+ return {
272
+ key,
273
+ content: `"${key}": {\n${imports}\n }`,
274
+ files
275
+ };
276
+ } catch (error) {
277
+ console.error(`[lib-resolver] Error processing pattern "${pattern}":`, error);
278
+ return {
279
+ key,
280
+ content: `"${key}": {}`,
281
+ files: []
282
+ };
283
+ }
284
+ }));
285
+ const moduleDefs = moduleResults.map((result) => result.content);
286
+ const content = `export default {\n ${moduleDefs.join(",\n ")}\n}`;
287
+ const fileHashes = /* @__PURE__ */ new Map();
288
+ const allFiles = moduleResults.flatMap((result) => result.files);
289
+ for (const file of allFiles) if (existsSync(file)) {
290
+ const stats = statSync(file);
291
+ const fileHash = createHash("md5").update(`${file}-${stats.mtimeMs}-${stats.size}`).digest("hex");
292
+ fileHashes.set(file, fileHash);
293
+ }
294
+ if (enableCache) {
295
+ if (cache.size >= maxCacheSize) {
296
+ const oldestKey = cache.keys().next().value;
297
+ if (oldestKey) cache.delete(oldestKey);
298
+ }
299
+ cache.set(configHash, {
300
+ content,
301
+ fileHashes,
302
+ timestamp: Date.now()
303
+ });
304
+ }
305
+ return content;
306
+ }
307
+ };
308
+ async function checkForFileChanges(entries, cachedFileHashes) {
309
+ try {
310
+ for (const pattern of Object.values(entries)) {
311
+ const files = await fg(pattern, { absolute: true });
312
+ for (const file of files) {
313
+ if (!existsSync(file)) return true;
314
+ const stats = statSync(file);
315
+ const currentFileHash = createHash("md5").update(`${file}-${stats.mtimeMs}-${stats.size}`).digest("hex");
316
+ const cachedHash = cachedFileHashes.get(file);
317
+ if (!cachedHash || cachedHash !== currentFileHash) return true;
318
+ }
319
+ for (const cachedFile of cachedFileHashes.keys()) if (!files.includes(cachedFile) && existsSync(cachedFile)) return true;
320
+ }
321
+ return false;
322
+ } catch (error) {
323
+ console.warn("[lib-resolver] Error checking file changes:", error);
324
+ return true;
325
+ }
326
+ }
327
+ }
328
+ function createLibResolver(options) {
329
+ return libResolverPlugin(merge({
330
+ entries: {
331
+ icons: "src/assets/icons/**/*",
332
+ layouts: "src/layouts/*.vue",
333
+ pages: "src/views/**/*.vue"
334
+ },
335
+ cache: true,
336
+ maxCacheSize: 50
337
+ }, options));
338
+ }
339
+
340
+ //#endregion
341
+ //#region src/plugins/mock.ts
342
+ function createMock(env, isBuild) {
343
+ const { VITE_BUILD_MOCK } = env;
344
+ if (!existsSync(resolve(cwd(), "src/mock"))) return;
345
+ return vitePluginFakeServer({
346
+ logger: !isBuild,
347
+ include: "src/mock",
348
+ infixName: false,
349
+ enableProd: isBuild && VITE_BUILD_MOCK === "true"
350
+ });
351
+ }
352
+
353
+ //#endregion
354
+ //#region src/plugins/openapi.ts
355
+ function createOpenAPI(options) {
356
+ return OpenAPI(options || { enabled: false });
357
+ }
358
+
359
+ //#endregion
360
+ //#region src/plugins/unocss.ts
361
+ function createUnocss() {
362
+ return Unocss();
363
+ }
364
+
365
+ //#endregion
366
+ //#region src/plugins/index.ts
367
+ function createVitePlugins(viteEnv, isBuild = false, config, type) {
368
+ const vitePlugins = [
369
+ vue(),
370
+ vueJsx(),
371
+ createLegacy(viteEnv),
372
+ createAutoImport(),
373
+ createComponents(),
374
+ createUnocss(),
375
+ createIcons(),
376
+ createMock(viteEnv, isBuild),
377
+ createInspector(viteEnv),
378
+ createOpenAPI(config.openapi),
379
+ createLibResolver(config.resolver),
380
+ appInfo(),
381
+ type === "module" ? [createDTS(), createInjectCSS()] : null,
382
+ isBuild ? createCompression(viteEnv) : null
383
+ ];
384
+ return vitePlugins.filter(Boolean);
385
+ }
386
+
387
+ //#endregion
388
+ //#region src/config/application.ts
389
+ function createDefaultAppConfig(config) {
390
+ return ({ mode, command }) => {
391
+ const root = cwd();
392
+ const isBuild = command === "build";
393
+ const timestamp = (/* @__PURE__ */ new Date()).getTime();
394
+ const env = loadEnv(mode, root);
395
+ const { VITE_OPEN_PROXY, VITE_BUILD_SOURCEMAP } = env;
396
+ const serverProxy = getServerProxy(env, !isBuild && VITE_OPEN_PROXY === "true");
397
+ const applicationConfig = {
398
+ base: "./",
399
+ server: {
400
+ open: true,
401
+ host: true,
402
+ proxy: serverProxy,
403
+ warmup: { clientFiles: ["./index.html"] }
404
+ },
405
+ optimizeDeps: { exclude: [
406
+ "pubinfo",
407
+ "@pubinfo/core",
408
+ "alova"
409
+ ] },
410
+ resolve: { alias: alias(root) },
411
+ build: {
412
+ outDir: mode === "production" ? "dist" : `dist-${mode}`,
413
+ sourcemap: VITE_BUILD_SOURCEMAP === "true",
414
+ reportCompressedSize: false,
415
+ chunkSizeWarningLimit: 2e3,
416
+ rolldownOptions: { output: {
417
+ entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`,
418
+ advancedChunks: { groups: [{
419
+ name: "pubinfo",
420
+ test: "pubinfo"
421
+ }] }
422
+ } }
423
+ },
424
+ plugins: createVitePlugins(env, isBuild, config, "app")
425
+ };
426
+ return applicationConfig;
427
+ };
428
+ }
429
+
430
+ //#endregion
431
+ //#region src/config/module.ts
432
+ function createDefaultModuleConfig(config) {
433
+ return ({ mode, command }) => {
434
+ const root = cwd();
435
+ const isBuild = command === "build";
436
+ const env = loadEnv(mode, root);
437
+ const applicationConfig = {
438
+ optimizeDeps: { exclude: [
439
+ "pubinfo",
440
+ "@pubinfo/core",
441
+ "alova"
442
+ ] },
443
+ resolve: { alias: alias(root) },
444
+ build: { rolldownOptions: {
445
+ preserveEntrySignatures: "allow-extension",
446
+ external: [
447
+ "vue",
448
+ "vue-router",
449
+ "pinia",
450
+ "unocss"
451
+ ]
452
+ } },
453
+ plugins: createVitePlugins(env, isBuild, config, "module")
454
+ };
455
+ return applicationConfig;
456
+ };
457
+ }
458
+
459
+ //#endregion
460
+ //#region src/config/index.ts
461
+ /**
462
+ * 构建应用配置
463
+ */
464
+ function definePubinfoConfig(config) {
465
+ return {
466
+ ...config,
467
+ vite: mergeViteConfig(createDefaultAppConfig(config), config)
468
+ };
469
+ }
470
+ /**
471
+ * 构建模块配置
472
+ */
473
+ function defineModuleConfig(config) {
474
+ return {
475
+ ...config,
476
+ vite: mergeViteConfig(createDefaultModuleConfig(config), config)
477
+ };
478
+ }
479
+ /**
480
+ * 合并默认Vite配置
481
+ */
482
+ function mergeViteConfig(defaultOptions, config = {}) {
483
+ const { vite: viteOptions = {} } = config;
484
+ return defineConfig(({ mode, command }) => {
485
+ return mergeConfig(defaultOptions({
486
+ mode,
487
+ command
488
+ }), typeof viteOptions === "function" ? viteOptions({
489
+ mode,
490
+ command
491
+ }) : viteOptions);
492
+ });
493
+ }
494
+
495
+ //#endregion
496
+ export { defineModuleConfig, definePubinfoConfig };
package/package.json CHANGED
@@ -1,54 +1,58 @@
1
1
  {
2
2
  "name": "@pubinfo/vite",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.9",
4
+ "version": "2.0.0-rc.2",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
8
- "default": "./dist/index.mjs"
8
+ "default": "./dist/index.js"
9
9
  }
10
10
  },
11
- "main": "./dist/index.mjs",
12
- "module": "./dist/index.mjs",
11
+ "main": "./dist/index.js",
12
+ "module": "./dist/index.js",
13
13
  "types": "./dist/index.d.ts",
14
14
  "files": [
15
15
  "dist"
16
16
  ],
17
17
  "peerDependencies": {
18
- "vue": "^3.5.13",
19
- "vue-i18n": "^10.0.5"
18
+ "vue": "^3.5.17",
19
+ "vue-i18n": "^10.0.7"
20
20
  },
21
21
  "dependencies": {
22
22
  "@pubinfo/unplugin-openapi": "^0.8.4",
23
- "@vitejs/plugin-legacy": "^6.0.2",
24
- "@vitejs/plugin-vue": "^5.2.1",
25
- "@vitejs/plugin-vue-jsx": "^4.1.1",
23
+ "@vitejs/plugin-legacy": "^7.2.1",
24
+ "@vitejs/plugin-vue": "^6.0.0",
25
+ "@vitejs/plugin-vue-jsx": "^5.0.1",
26
26
  "abort-controller": "^3.0.0",
27
27
  "boxen": "^8.0.1",
28
28
  "chalk": "^5.4.1",
29
- "consola": "^3.4.0",
29
+ "consola": "^3.4.2",
30
+ "fast-glob": "^3.3.3",
30
31
  "fs-extra": "^11.3.0",
31
32
  "jszip": "^3.10.1",
32
- "terser": "^5.39.0",
33
- "unocss": "^65.5.0",
34
- "unplugin-auto-import": "^19.1.1",
35
- "unplugin-icons": "^22.1.0",
36
- "unplugin-vue-components": "^28.4.1",
37
- "vite": "^6.2.0",
33
+ "lodash-es": "^4.17.21",
34
+ "rolldown-vite": "^7.1.2",
35
+ "terser": "^5.43.1",
36
+ "unocss": "^66.4.2",
37
+ "unplugin-auto-import": "^20.0.0",
38
+ "unplugin-icons": "^22.2.0",
39
+ "unplugin-vue-components": "^29.0.0",
38
40
  "vite-plugin-compression": "^0.5.1",
41
+ "vite-plugin-dts": "^4.5.4",
39
42
  "vite-plugin-env-runtime": "^0.3.6",
40
43
  "vite-plugin-fake-server": "^2.2.0",
41
- "vite-plugin-vue-devtools": "^7.7.2"
44
+ "vite-plugin-lib-inject-css": "^2.2.2",
45
+ "vite-plugin-vue-devtools": "^8.0.0"
42
46
  },
43
47
  "devDependencies": {
44
48
  "@types/fs-extra": "^11.0.4",
45
- "@types/node": "^22.13.9",
46
- "unbuild": "^3.5.0",
47
- "vue": "^3.5.13",
48
- "vue-i18n": "^10.0.5"
49
+ "@types/lodash-es": "^4.17.12",
50
+ "@types/node": "^24.0.10",
51
+ "vue": "^3.5.17",
52
+ "vue-i18n": "^10.0.7"
49
53
  },
50
54
  "scripts": {
51
- "stub": "unbuild --stub",
52
- "build": "unbuild"
55
+ "dev": "tsdown --watch",
56
+ "build": "tsdown"
53
57
  }
54
58
  }
package/dist/index.d.mts DELETED
@@ -1,28 +0,0 @@
1
- import * as _pubinfo_unplugin_openapi from '@pubinfo/unplugin-openapi';
2
- import { Options } from '@pubinfo/unplugin-openapi';
3
- import { UserConfig, UserConfigFnObject } from 'vite';
4
- export * from 'vite';
5
-
6
- interface PubinfoConfig {
7
- /** `vite` */
8
- vite?: UserConfig | UserConfigFnObject;
9
- /** `@pubinfo/unplugin-openapi` */
10
- openapi?: Options;
11
- }
12
-
13
- /**
14
- * 构建应用配置
15
- */
16
- declare function definePubinfoConfig(config: PubinfoConfig): {
17
- vite: UserConfigFnObject;
18
- openapi?: _pubinfo_unplugin_openapi.Options;
19
- };
20
- /**
21
- * 构建模块配置
22
- */
23
- declare function defineModuleConfig(config: PubinfoConfig): {
24
- vite: UserConfigFnObject;
25
- openapi?: _pubinfo_unplugin_openapi.Options;
26
- };
27
-
28
- export { type PubinfoConfig, defineModuleConfig, definePubinfoConfig };
package/dist/index.mjs DELETED
@@ -1,388 +0,0 @@
1
- import { loadEnv, defineConfig, mergeConfig } from 'vite';
2
- export * from 'vite';
3
- import { cwd } from 'node:process';
4
- import chalk from 'chalk';
5
- import consola from 'consola';
6
- import { createRequire } from 'node:module';
7
- import { join, resolve } from 'node:path';
8
- import vue from '@vitejs/plugin-vue';
9
- import vueJsx from '@vitejs/plugin-vue-jsx';
10
- import autoImport from 'unplugin-auto-import/vite';
11
- import IconsResolver from 'unplugin-icons/resolver';
12
- import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
13
- import components from 'unplugin-vue-components/vite';
14
- import compression from 'vite-plugin-compression';
15
- import Icons from 'unplugin-icons/vite';
16
- import boxen from 'boxen';
17
- import VueDevTools from 'vite-plugin-vue-devtools';
18
- import vueLegacy from '@vitejs/plugin-legacy';
19
- import { existsSync } from 'node:fs';
20
- import { vitePluginFakeServer } from 'vite-plugin-fake-server';
21
- import OpenAPI from '@pubinfo/unplugin-openapi/vite';
22
- import Unocss from 'unocss/vite';
23
-
24
- function alias(root) {
25
- const resolvePath = (name) => join(root, name);
26
- const resolveDeps = (name, path) => join(createRequire(import.meta.url).resolve(name), path);
27
- return {
28
- "@": resolvePath("src"),
29
- "#": resolvePath("types"),
30
- // 提供路径别名给 @pubinfo/core 直接调用项目中的文件
31
- "pubinfo:project": resolvePath("src"),
32
- // 显示的列出导出的目录
33
- // '.pubinfo': resolvePath('.pubinfo/'),
34
- // '.pubinfo/api': resolvePath('.pubinfo/api/'),
35
- // '.pubinfo/assets': resolvePath('.pubinfo/assets/'),
36
- // '.pubinfo/config': resolvePath('.pubinfo/config/'),
37
- // '.pubinfo/directives': resolvePath('.pubinfo/directives/'),
38
- // '.pubinfo/layout': resolvePath('.pubinfo/layout/'),
39
- // '.pubinfo/locales': resolvePath('.pubinfo/locales/'),
40
- // '.pubinfo/router': resolvePath('.pubinfo/router/'),
41
- // '.pubinfo/store': resolvePath('.pubinfo/store/'),
42
- // '.pubinfo/styles': resolvePath('.pubinfo/styles/'),
43
- // '.pubinfo/themes': resolvePath('.pubinfo/themes/'),
44
- // '.pubinfo/types': resolvePath('.pubinfo/types/'),
45
- // '.pubinfo/utils': resolvePath('.pubinfo/utils/'),
46
- // '.pubinfo/vue': resolvePath('.pubinfo/vue/'),
47
- // deps
48
- "vue": resolveDeps("vue", "../"),
49
- "vue-router": resolveDeps("vue-router", "../"),
50
- "pinia": resolveDeps("pinia", "../"),
51
- "unocss": resolveDeps("unocss", "../")
52
- };
53
- }
54
-
55
- function getServerProxy(env, isProxy) {
56
- if (!isProxy) {
57
- return {};
58
- }
59
- const targetPrefix = "VITE_APP_API_";
60
- const proxyKey = Object.keys(env).filter((key) => key.startsWith(targetPrefix));
61
- const serverProxy = {};
62
- for (const envKey of proxyKey) {
63
- const url = env[envKey];
64
- const { pathname } = new URL(url);
65
- const pk = `${pathname}/proxy`;
66
- if (pk in serverProxy) {
67
- consola.error(`The proxy key ${chalk.bold.redBright(envKey)} \u279C ${chalk.bold.yellowBright(url)} already exists`);
68
- } else {
69
- serverProxy[pk] = {
70
- target: url,
71
- changeOrigin: true,
72
- rewrite: (path) => path.replace(pk, ""),
73
- secure: false
74
- };
75
- }
76
- }
77
- return serverProxy;
78
- }
79
-
80
- function createAutoImport() {
81
- return autoImport({
82
- imports: [
83
- "vue",
84
- "vue-router",
85
- // 'vue-i18n',
86
- "pinia",
87
- {
88
- pubinfo: [
89
- "useAuth"
90
- ]
91
- }
92
- ],
93
- // 解决代码混淆后出现的h和vue导入的h变量命名重复的问题
94
- ignore: ["h"],
95
- dts: "./types/auto-imports.d.ts",
96
- dirs: [
97
- "./src/composables/**/*"
98
- ],
99
- resolvers: [
100
- AntDesignVueResolver(),
101
- IconsResolver({
102
- prefix: "i"
103
- })
104
- ]
105
- });
106
- }
107
-
108
- function createComponents() {
109
- return components({
110
- dirs: [
111
- "src/components"
112
- ],
113
- directives: true,
114
- include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
115
- resolvers: [
116
- IconsResolver(),
117
- AntDesignVueResolver({
118
- resolveIcons: true,
119
- importStyle: false
120
- }),
121
- {
122
- type: "component",
123
- resolve(name) {
124
- const components2 = [
125
- "PubinfoApp",
126
- "PubinfoProvider",
127
- "PubinfoIcon"
128
- ];
129
- if (components2.includes(name)) {
130
- return { name, from: "pubinfo" };
131
- }
132
- }
133
- }
134
- ],
135
- dts: "./types/components.d.ts"
136
- });
137
- }
138
-
139
- function createCompression(env) {
140
- const { VITE_BUILD_COMPRESS } = env;
141
- const compressList = VITE_BUILD_COMPRESS?.split(",") ?? [];
142
- const plugin = [];
143
- if (compressList.includes("gzip")) {
144
- plugin.push(
145
- compression({
146
- ext: ".gz",
147
- deleteOriginFile: false
148
- })
149
- );
150
- }
151
- if (compressList.includes("brotli")) {
152
- plugin.push(
153
- compression({
154
- ext: ".br",
155
- algorithm: "brotliCompress",
156
- deleteOriginFile: false
157
- })
158
- );
159
- }
160
- return plugin;
161
- }
162
-
163
- function createIcons() {
164
- return Icons({
165
- autoInstall: false
166
- });
167
- }
168
-
169
- class Ctx {
170
- options;
171
- setOptions(options) {
172
- this.options = options;
173
- }
174
- async createInfo() {
175
- console.log(
176
- boxen(
177
- `\u6B22\u8FCE\u4F7F\u7528${chalk.bold.greenBright(" \u6280\u672F\u5E95\u5EA7\u7BA1\u7406\u7CFB\u7EDF ")}
178
-
179
- ${chalk.green("\u4F7F\u7528\u6587\u6863\u5730\u5740")} ${chalk.green("\u279C")} https://134.108.39.195:9090/docs`,
180
- {
181
- padding: 1,
182
- margin: 1,
183
- align: "center",
184
- borderColor: "yellowBright",
185
- borderStyle: "round"
186
- }
187
- )
188
- );
189
- }
190
- }
191
- const ctx = new Ctx();
192
- function appInfo() {
193
- return {
194
- name: "appInfo",
195
- apply: "serve",
196
- enforce: "pre",
197
- configResolved(configuration) {
198
- const root = configuration.root;
199
- ctx.setOptions({
200
- root
201
- });
202
- },
203
- async buildStart() {
204
- ctx.createInfo();
205
- },
206
- configureServer(server) {
207
- const _printUrls = server.printUrls;
208
- server.printUrls = () => {
209
- console.log(` ${chalk.green("\u279C")} ${chalk.bold.bgBlueBright(` PUBINFO `)}${chalk.bold.bgYellowBright(` \u524D\u7AEF\u57FA\u7840\u6846\u67B6 `)}`);
210
- _printUrls();
211
- };
212
- }
213
- };
214
- }
215
-
216
- function createInspector(env) {
217
- const { VITE_APP_INSPECTOR } = env;
218
- if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") {
219
- return VueDevTools();
220
- } else {
221
- return null;
222
- }
223
- }
224
-
225
- function createLegacy(env) {
226
- if (env.VITE_BUILD_LEGACY !== "true") {
227
- return false;
228
- }
229
- return vueLegacy({
230
- modernPolyfills: [
231
- "es.array.at",
232
- "es.array.find-last"
233
- ],
234
- additionalLegacyPolyfills: ["abort-controller/polyfill"]
235
- });
236
- }
237
-
238
- function createMock(env, isBuild) {
239
- const { VITE_BUILD_MOCK } = env;
240
- if (!existsSync(resolve(cwd(), "src/mock"))) {
241
- return;
242
- }
243
- return vitePluginFakeServer({
244
- logger: !isBuild,
245
- include: "src/mock",
246
- infixName: false,
247
- enableProd: isBuild && VITE_BUILD_MOCK === "true"
248
- });
249
- }
250
-
251
- function createOpenAPI(options) {
252
- return OpenAPI(options || { enabled: false });
253
- }
254
-
255
- function createUnocss() {
256
- return Unocss();
257
- }
258
-
259
- function createVitePlugins(viteEnv, isBuild = false, config) {
260
- const vitePlugins = [
261
- vue(),
262
- vueJsx(),
263
- createLegacy(viteEnv),
264
- createAutoImport(),
265
- createComponents(),
266
- createUnocss(),
267
- createIcons(),
268
- createMock(viteEnv, isBuild),
269
- createInspector(viteEnv),
270
- createOpenAPI(config.openapi),
271
- appInfo()
272
- ];
273
- const buildPlugins = () => [
274
- ...createCompression(viteEnv)
275
- ];
276
- if (isBuild) {
277
- vitePlugins.push(...buildPlugins());
278
- }
279
- return vitePlugins.filter(Boolean);
280
- }
281
-
282
- function createDefaultAppConfig(config) {
283
- return ({ mode, command }) => {
284
- const root = cwd();
285
- const isBuild = command === "build";
286
- const timestamp = (/* @__PURE__ */ new Date()).getTime();
287
- const env = loadEnv(mode, root);
288
- const { VITE_OPEN_PROXY, VITE_BUILD_SOURCEMAP } = env;
289
- const serverProxy = getServerProxy(env, !isBuild && VITE_OPEN_PROXY === "true");
290
- const applicationConfig = {
291
- base: "./",
292
- server: {
293
- open: true,
294
- host: true,
295
- proxy: serverProxy,
296
- warmup: {
297
- clientFiles: [
298
- "./index.html"
299
- ]
300
- }
301
- },
302
- // To fix some dev problems
303
- optimizeDeps: {
304
- exclude: [
305
- "pubinfo",
306
- "@pubinfo/core",
307
- "alova"
308
- ]
309
- },
310
- resolve: {
311
- alias: alias(root)
312
- },
313
- build: {
314
- outDir: mode === "production" ? "dist" : `dist-${mode}`,
315
- sourcemap: VITE_BUILD_SOURCEMAP === "true",
316
- reportCompressedSize: false,
317
- chunkSizeWarningLimit: 2e3,
318
- rollupOptions: {
319
- output: {
320
- entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`,
321
- manualChunks: {
322
- pubinfo: ["pubinfo"]
323
- }
324
- }
325
- }
326
- },
327
- plugins: createVitePlugins(env, isBuild, config)
328
- };
329
- return applicationConfig;
330
- };
331
- }
332
-
333
- function createDefaultModuleConfig(config) {
334
- return ({ mode, command }) => {
335
- const root = cwd();
336
- const isBuild = command === "build";
337
- const env = loadEnv(mode, root);
338
- const applicationConfig = {
339
- // To fix some dev problems
340
- optimizeDeps: {
341
- exclude: [
342
- "pubinfo",
343
- "@pubinfo/core",
344
- "alova"
345
- ]
346
- },
347
- resolve: {
348
- alias: alias(root)
349
- },
350
- build: {
351
- rollupOptions: {
352
- external: [
353
- "vue",
354
- "vue-router",
355
- "pinia",
356
- "unocss"
357
- ]
358
- }
359
- },
360
- plugins: createVitePlugins(env, isBuild, config)
361
- };
362
- return applicationConfig;
363
- };
364
- }
365
-
366
- function definePubinfoConfig(config) {
367
- return {
368
- ...config,
369
- vite: mergeViteConfig(createDefaultAppConfig(config), config)
370
- };
371
- }
372
- function defineModuleConfig(config) {
373
- return {
374
- ...config,
375
- vite: mergeViteConfig(createDefaultModuleConfig(config), config)
376
- };
377
- }
378
- function mergeViteConfig(defaultOptions, config = {}) {
379
- const { vite: viteOptions = {} } = config;
380
- return defineConfig(({ mode, command }) => {
381
- return mergeConfig(
382
- defaultOptions({ mode, command }),
383
- typeof viteOptions === "function" ? viteOptions({ mode, command }) : viteOptions
384
- );
385
- });
386
- }
387
-
388
- export { defineModuleConfig, definePubinfoConfig };