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