@pubinfo/vite 2.0.0-beta.31 → 2.0.0-beta.33

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,29 +1,31 @@
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
- export * from 'vite-plugin-fake-server/client';
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";
6
6
 
7
+ //#region src/interface.d.ts
7
8
  interface PubinfoConfig {
8
- /** `vite` */
9
- vite?: UserConfig | UserConfigFnObject;
10
- /** `@pubinfo/unplugin-openapi` */
11
- openapi?: Options;
9
+ /** `vite` */
10
+ vite?: UserConfig | UserConfigFnObject;
11
+ /** `@pubinfo/unplugin-openapi` */
12
+ openapi?: Options;
12
13
  }
13
-
14
+ //#endregion
15
+ //#region src/config/index.d.ts
14
16
  /**
15
17
  * 构建应用配置
16
18
  */
17
19
  declare function definePubinfoConfig(config: PubinfoConfig): {
18
- vite: UserConfigFnObject;
19
- openapi?: _pubinfo_unplugin_openapi.Options;
20
+ vite: UserConfigFnObject;
21
+ openapi?: _pubinfo_unplugin_openapi0.Options;
20
22
  };
21
23
  /**
22
24
  * 构建模块配置
23
25
  */
24
26
  declare function defineModuleConfig(config: PubinfoConfig): {
25
- vite: UserConfigFnObject;
26
- openapi?: _pubinfo_unplugin_openapi.Options;
27
+ vite: UserConfigFnObject;
28
+ openapi?: _pubinfo_unplugin_openapi0.Options;
27
29
  };
28
-
29
- export { type PubinfoConfig, defineModuleConfig, definePubinfoConfig };
30
+ //#endregion
31
+ export { PubinfoConfig, defineModuleConfig, definePubinfoConfig };
package/dist/index.js ADDED
@@ -0,0 +1,353 @@
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, 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 Icons from "unplugin-icons/vite";
15
+ import boxen from "boxen";
16
+ import VueDevTools from "vite-plugin-vue-devtools";
17
+ import vueLegacy from "@vitejs/plugin-legacy";
18
+ import { existsSync } from "node:fs";
19
+ import { vitePluginFakeServer } from "vite-plugin-fake-server";
20
+ import OpenAPI from "@pubinfo/unplugin-openapi/vite";
21
+ import Unocss from "unocss/vite";
22
+
23
+ export * from "rolldown-vite"
24
+
25
+ export * from "vite-plugin-fake-server/client"
26
+
27
+ //#region src/helper/alias.ts
28
+ function alias(root) {
29
+ const resolvePath = (name) => join(root, name);
30
+ const resolveDeps = (name, path) => join(createRequire(import.meta.url).resolve(name), path);
31
+ return {
32
+ "@": resolvePath("src"),
33
+ "#": resolvePath("types"),
34
+ "pubinfo:project": resolvePath("src"),
35
+ "vue": resolveDeps("vue", "../"),
36
+ "vue-router": resolveDeps("vue-router", "../"),
37
+ "pinia": resolveDeps("pinia", "../"),
38
+ "unocss": resolveDeps("unocss", "../")
39
+ };
40
+ }
41
+
42
+ //#endregion
43
+ //#region src/helper/index.ts
44
+ function getServerProxy(env, isProxy) {
45
+ if (!isProxy) return {};
46
+ const targetPrefix = "VITE_APP_API_";
47
+ const proxyKey = Object.keys(env).filter((key) => key.startsWith(targetPrefix));
48
+ const serverProxy = {};
49
+ for (const envKey of proxyKey) {
50
+ const url = env[envKey];
51
+ const { pathname } = new URL(url);
52
+ const pk = `${pathname}/proxy`;
53
+ if (pk in serverProxy) consola.error(`The proxy key ${chalk.bold.redBright(envKey)} ➜ ${chalk.bold.yellowBright(url)} already exists`);
54
+ else serverProxy[pk] = {
55
+ target: url,
56
+ changeOrigin: true,
57
+ rewrite: (path) => path.replace(pk, ""),
58
+ secure: false
59
+ };
60
+ }
61
+ return serverProxy;
62
+ }
63
+
64
+ //#endregion
65
+ //#region src/plugins/auto-import.ts
66
+ function createAutoImport() {
67
+ return autoImport({
68
+ imports: [
69
+ "vue",
70
+ "vue-router",
71
+ "pinia",
72
+ { pubinfo: ["useAuth"] }
73
+ ],
74
+ ignore: ["h"],
75
+ dts: "./types/auto-imports.d.ts",
76
+ dirs: ["./src/composables/**/*"],
77
+ resolvers: [AntDesignVueResolver(), IconsResolver({ prefix: "i" })]
78
+ });
79
+ }
80
+
81
+ //#endregion
82
+ //#region src/plugins/components.ts
83
+ function createComponents() {
84
+ return components({
85
+ dirs: ["src/components"],
86
+ directives: true,
87
+ include: [
88
+ /\.vue$/,
89
+ /\.vue\?vue/,
90
+ /\.tsx$/
91
+ ],
92
+ resolvers: [
93
+ IconsResolver(),
94
+ AntDesignVueResolver({
95
+ resolveIcons: true,
96
+ importStyle: false
97
+ }),
98
+ {
99
+ type: "component",
100
+ resolve(name) {
101
+ const components$1 = [
102
+ "PubinfoApp",
103
+ "PubinfoProvider",
104
+ "PubinfoIcon"
105
+ ];
106
+ if (components$1.includes(name)) return {
107
+ name,
108
+ from: "pubinfo"
109
+ };
110
+ }
111
+ }
112
+ ],
113
+ dts: "./types/components.d.ts"
114
+ });
115
+ }
116
+
117
+ //#endregion
118
+ //#region src/plugins/compression.ts
119
+ function createCompression(env) {
120
+ const { VITE_BUILD_COMPRESS } = env;
121
+ const compressList = VITE_BUILD_COMPRESS?.split(",") ?? [];
122
+ const plugin = [];
123
+ if (compressList.includes("gzip")) plugin.push(compression({
124
+ ext: ".gz",
125
+ deleteOriginFile: false
126
+ }));
127
+ if (compressList.includes("brotli")) plugin.push(compression({
128
+ ext: ".br",
129
+ algorithm: "brotliCompress",
130
+ deleteOriginFile: false
131
+ }));
132
+ return plugin;
133
+ }
134
+
135
+ //#endregion
136
+ //#region src/plugins/icon.ts
137
+ function createIcons() {
138
+ return Icons({ autoInstall: false });
139
+ }
140
+
141
+ //#endregion
142
+ //#region src/plugins/info.ts
143
+ var Ctx = class {
144
+ options;
145
+ setOptions(options) {
146
+ this.options = options;
147
+ }
148
+ async createInfo() {
149
+ console.log(boxen(`\
150
+ 欢迎使用${chalk.bold.greenBright(" 技术底座管理系统 ")}\n
151
+ ${chalk.green("使用文档地址")} ${chalk.green("➜")} https://134.108.39.195:9090/docs`, {
152
+ padding: 1,
153
+ margin: 1,
154
+ align: "center",
155
+ borderColor: "yellowBright",
156
+ borderStyle: "round"
157
+ }));
158
+ }
159
+ };
160
+ const ctx = new Ctx();
161
+ function appInfo() {
162
+ return {
163
+ name: "appInfo",
164
+ apply: "serve",
165
+ enforce: "pre",
166
+ configResolved(configuration) {
167
+ const root = configuration.root;
168
+ ctx.setOptions({ root });
169
+ },
170
+ async buildStart() {
171
+ ctx.createInfo();
172
+ },
173
+ configureServer(server) {
174
+ const _printUrls = server.printUrls;
175
+ server.printUrls = () => {
176
+ console.log(` ${chalk.green("➜")} ${chalk.bold.bgBlueBright(` PUBINFO `)}${chalk.bold.bgYellowBright(` 前端基础框架 `)}`);
177
+ _printUrls();
178
+ };
179
+ }
180
+ };
181
+ }
182
+
183
+ //#endregion
184
+ //#region src/plugins/inspector.ts
185
+ function createInspector(env) {
186
+ const { VITE_APP_INSPECTOR } = env;
187
+ if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") return VueDevTools();
188
+ else return null;
189
+ }
190
+
191
+ //#endregion
192
+ //#region src/plugins/legacy.ts
193
+ function createLegacy(env) {
194
+ if (env.VITE_BUILD_LEGACY !== "true") return false;
195
+ return vueLegacy({
196
+ modernPolyfills: ["es.array.at", "es.array.find-last"],
197
+ additionalLegacyPolyfills: ["abort-controller/polyfill"]
198
+ });
199
+ }
200
+
201
+ //#endregion
202
+ //#region src/plugins/mock.ts
203
+ function createMock(env, isBuild) {
204
+ const { VITE_BUILD_MOCK } = env;
205
+ if (!existsSync(resolve(cwd(), "src/mock"))) return;
206
+ return vitePluginFakeServer({
207
+ logger: !isBuild,
208
+ include: "src/mock",
209
+ infixName: false,
210
+ enableProd: isBuild && VITE_BUILD_MOCK === "true"
211
+ });
212
+ }
213
+
214
+ //#endregion
215
+ //#region src/plugins/openapi.ts
216
+ function createOpenAPI(options) {
217
+ return OpenAPI(options || { enabled: false });
218
+ }
219
+
220
+ //#endregion
221
+ //#region src/plugins/unocss.ts
222
+ function createUnocss() {
223
+ return Unocss();
224
+ }
225
+
226
+ //#endregion
227
+ //#region src/plugins/index.ts
228
+ function createVitePlugins(viteEnv, isBuild = false, config) {
229
+ const vitePlugins = [
230
+ vue(),
231
+ vueJsx(),
232
+ createLegacy(viteEnv),
233
+ createAutoImport(),
234
+ createComponents(),
235
+ createUnocss(),
236
+ createIcons(),
237
+ createMock(viteEnv, isBuild),
238
+ createInspector(viteEnv),
239
+ createOpenAPI(config.openapi),
240
+ appInfo()
241
+ ];
242
+ const buildPlugins = () => [...createCompression(viteEnv)];
243
+ if (isBuild) vitePlugins.push(...buildPlugins());
244
+ return vitePlugins.filter(Boolean);
245
+ }
246
+
247
+ //#endregion
248
+ //#region src/config/application.ts
249
+ function createDefaultAppConfig(config) {
250
+ return ({ mode, command }) => {
251
+ const root = cwd();
252
+ const isBuild = command === "build";
253
+ const timestamp = (/* @__PURE__ */ new Date()).getTime();
254
+ const env = loadEnv(mode, root);
255
+ const { VITE_OPEN_PROXY, VITE_BUILD_SOURCEMAP } = env;
256
+ const serverProxy = getServerProxy(env, !isBuild && VITE_OPEN_PROXY === "true");
257
+ const applicationConfig = {
258
+ base: "./",
259
+ server: {
260
+ open: true,
261
+ host: true,
262
+ proxy: serverProxy,
263
+ warmup: { clientFiles: ["./index.html"] }
264
+ },
265
+ optimizeDeps: { exclude: [
266
+ "pubinfo",
267
+ "@pubinfo/core",
268
+ "alova"
269
+ ] },
270
+ resolve: { alias: alias(root) },
271
+ build: {
272
+ outDir: mode === "production" ? "dist" : `dist-${mode}`,
273
+ sourcemap: VITE_BUILD_SOURCEMAP === "true",
274
+ reportCompressedSize: false,
275
+ chunkSizeWarningLimit: 2e3,
276
+ rollupOptions: { output: {
277
+ entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`,
278
+ advancedChunks: { groups: [{
279
+ name: "pubinfo",
280
+ test: "pubinfo"
281
+ }] }
282
+ } }
283
+ },
284
+ plugins: createVitePlugins(env, isBuild, config)
285
+ };
286
+ return applicationConfig;
287
+ };
288
+ }
289
+
290
+ //#endregion
291
+ //#region src/config/module.ts
292
+ function createDefaultModuleConfig(config) {
293
+ return ({ mode, command }) => {
294
+ const root = cwd();
295
+ const isBuild = command === "build";
296
+ const env = loadEnv(mode, root);
297
+ const applicationConfig = {
298
+ optimizeDeps: { exclude: [
299
+ "pubinfo",
300
+ "@pubinfo/core",
301
+ "alova"
302
+ ] },
303
+ resolve: { alias: alias(root) },
304
+ build: { rollupOptions: { external: [
305
+ "vue",
306
+ "vue-router",
307
+ "pinia",
308
+ "unocss"
309
+ ] } },
310
+ plugins: createVitePlugins(env, isBuild, config)
311
+ };
312
+ return applicationConfig;
313
+ };
314
+ }
315
+
316
+ //#endregion
317
+ //#region src/config/index.ts
318
+ /**
319
+ * 构建应用配置
320
+ */
321
+ function definePubinfoConfig(config) {
322
+ return {
323
+ ...config,
324
+ vite: mergeViteConfig(createDefaultAppConfig(config), config)
325
+ };
326
+ }
327
+ /**
328
+ * 构建模块配置
329
+ */
330
+ function defineModuleConfig(config) {
331
+ return {
332
+ ...config,
333
+ vite: mergeViteConfig(createDefaultModuleConfig(config), config)
334
+ };
335
+ }
336
+ /**
337
+ * 合并默认Vite配置
338
+ */
339
+ function mergeViteConfig(defaultOptions, config = {}) {
340
+ const { vite: viteOptions = {} } = config;
341
+ return defineConfig(({ mode, command }) => {
342
+ return mergeConfig(defaultOptions({
343
+ mode,
344
+ command
345
+ }), typeof viteOptions === "function" ? viteOptions({
346
+ mode,
347
+ command
348
+ }) : viteOptions);
349
+ });
350
+ }
351
+
352
+ //#endregion
353
+ export { defineModuleConfig, definePubinfoConfig };
package/package.json CHANGED
@@ -1,54 +1,53 @@
1
1
  {
2
2
  "name": "@pubinfo/vite",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.31",
4
+ "version": "2.0.0-beta.33",
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.16",
18
+ "vue": "^3.5.17",
19
19
  "vue-i18n": "^10.0.7"
20
20
  },
21
21
  "dependencies": {
22
22
  "@pubinfo/unplugin-openapi": "^0.8.4",
23
23
  "@vitejs/plugin-legacy": "^6.1.1",
24
- "@vitejs/plugin-vue": "^5.2.4",
25
- "@vitejs/plugin-vue-jsx": "^4.2.0",
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
29
  "consola": "^3.4.2",
30
30
  "fs-extra": "^11.3.0",
31
31
  "jszip": "^3.10.1",
32
- "terser": "^5.40.0",
32
+ "rolldown-vite": "^6.3.21",
33
+ "terser": "^5.43.1",
33
34
  "unocss": "^65.5.0",
34
35
  "unplugin-auto-import": "^19.3.0",
35
36
  "unplugin-icons": "^22.1.0",
36
- "unplugin-vue-components": "^28.7.0",
37
- "vite": "^6.3.5",
37
+ "unplugin-vue-components": "^28.8.0",
38
38
  "vite-plugin-compression": "^0.5.1",
39
39
  "vite-plugin-env-runtime": "^0.3.6",
40
40
  "vite-plugin-fake-server": "^2.2.0",
41
- "vite-plugin-vue-devtools": "^7.7.6"
41
+ "vite-plugin-vue-devtools": "^7.7.7"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/fs-extra": "^11.0.4",
45
- "@types/node": "^22.15.27",
46
- "unbuild": "^3.5.0",
47
- "vue": "^3.5.16",
45
+ "@types/node": "^24.0.10",
46
+ "vue": "^3.5.17",
48
47
  "vue-i18n": "^10.0.7"
49
48
  },
50
49
  "scripts": {
51
- "stub": "unbuild --stub",
52
- "build": "unbuild"
50
+ "stub": "tsdown --watch",
51
+ "build": "tsdown"
53
52
  }
54
53
  }
package/dist/index.d.mts DELETED
@@ -1,29 +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
- export * from 'vite-plugin-fake-server/client';
6
-
7
- interface PubinfoConfig {
8
- /** `vite` */
9
- vite?: UserConfig | UserConfigFnObject;
10
- /** `@pubinfo/unplugin-openapi` */
11
- openapi?: Options;
12
- }
13
-
14
- /**
15
- * 构建应用配置
16
- */
17
- declare function definePubinfoConfig(config: PubinfoConfig): {
18
- vite: UserConfigFnObject;
19
- openapi?: _pubinfo_unplugin_openapi.Options;
20
- };
21
- /**
22
- * 构建模块配置
23
- */
24
- declare function defineModuleConfig(config: PubinfoConfig): {
25
- vite: UserConfigFnObject;
26
- openapi?: _pubinfo_unplugin_openapi.Options;
27
- };
28
-
29
- export { type PubinfoConfig, defineModuleConfig, definePubinfoConfig };
package/dist/index.mjs DELETED
@@ -1,389 +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
- export * from 'vite-plugin-fake-server/client';
24
-
25
- function alias(root) {
26
- const resolvePath = (name) => join(root, name);
27
- const resolveDeps = (name, path) => join(createRequire(import.meta.url).resolve(name), path);
28
- return {
29
- "@": resolvePath("src"),
30
- "#": resolvePath("types"),
31
- // 提供路径别名给 @pubinfo/core 直接调用项目中的文件
32
- "pubinfo:project": resolvePath("src"),
33
- // 显示的列出导出的目录
34
- // '.pubinfo': resolvePath('.pubinfo/'),
35
- // '.pubinfo/api': resolvePath('.pubinfo/api/'),
36
- // '.pubinfo/assets': resolvePath('.pubinfo/assets/'),
37
- // '.pubinfo/config': resolvePath('.pubinfo/config/'),
38
- // '.pubinfo/directives': resolvePath('.pubinfo/directives/'),
39
- // '.pubinfo/layout': resolvePath('.pubinfo/layout/'),
40
- // '.pubinfo/locales': resolvePath('.pubinfo/locales/'),
41
- // '.pubinfo/router': resolvePath('.pubinfo/router/'),
42
- // '.pubinfo/store': resolvePath('.pubinfo/store/'),
43
- // '.pubinfo/styles': resolvePath('.pubinfo/styles/'),
44
- // '.pubinfo/themes': resolvePath('.pubinfo/themes/'),
45
- // '.pubinfo/types': resolvePath('.pubinfo/types/'),
46
- // '.pubinfo/utils': resolvePath('.pubinfo/utils/'),
47
- // '.pubinfo/vue': resolvePath('.pubinfo/vue/'),
48
- // deps
49
- "vue": resolveDeps("vue", "../"),
50
- "vue-router": resolveDeps("vue-router", "../"),
51
- "pinia": resolveDeps("pinia", "../"),
52
- "unocss": resolveDeps("unocss", "../")
53
- };
54
- }
55
-
56
- function getServerProxy(env, isProxy) {
57
- if (!isProxy) {
58
- return {};
59
- }
60
- const targetPrefix = "VITE_APP_API_";
61
- const proxyKey = Object.keys(env).filter((key) => key.startsWith(targetPrefix));
62
- const serverProxy = {};
63
- for (const envKey of proxyKey) {
64
- const url = env[envKey];
65
- const { pathname } = new URL(url);
66
- const pk = `${pathname}/proxy`;
67
- if (pk in serverProxy) {
68
- consola.error(`The proxy key ${chalk.bold.redBright(envKey)} \u279C ${chalk.bold.yellowBright(url)} already exists`);
69
- } else {
70
- serverProxy[pk] = {
71
- target: url,
72
- changeOrigin: true,
73
- rewrite: (path) => path.replace(pk, ""),
74
- secure: false
75
- };
76
- }
77
- }
78
- return serverProxy;
79
- }
80
-
81
- function createAutoImport() {
82
- return autoImport({
83
- imports: [
84
- "vue",
85
- "vue-router",
86
- // 'vue-i18n',
87
- "pinia",
88
- {
89
- pubinfo: [
90
- "useAuth"
91
- ]
92
- }
93
- ],
94
- // 解决代码混淆后出现的h和vue导入的h变量命名重复的问题
95
- ignore: ["h"],
96
- dts: "./types/auto-imports.d.ts",
97
- dirs: [
98
- "./src/composables/**/*"
99
- ],
100
- resolvers: [
101
- AntDesignVueResolver(),
102
- IconsResolver({
103
- prefix: "i"
104
- })
105
- ]
106
- });
107
- }
108
-
109
- function createComponents() {
110
- return components({
111
- dirs: [
112
- "src/components"
113
- ],
114
- directives: true,
115
- include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
116
- resolvers: [
117
- IconsResolver(),
118
- AntDesignVueResolver({
119
- resolveIcons: true,
120
- importStyle: false
121
- }),
122
- {
123
- type: "component",
124
- resolve(name) {
125
- const components2 = [
126
- "PubinfoApp",
127
- "PubinfoProvider",
128
- "PubinfoIcon"
129
- ];
130
- if (components2.includes(name)) {
131
- return { name, from: "pubinfo" };
132
- }
133
- }
134
- }
135
- ],
136
- dts: "./types/components.d.ts"
137
- });
138
- }
139
-
140
- function createCompression(env) {
141
- const { VITE_BUILD_COMPRESS } = env;
142
- const compressList = VITE_BUILD_COMPRESS?.split(",") ?? [];
143
- const plugin = [];
144
- if (compressList.includes("gzip")) {
145
- plugin.push(
146
- compression({
147
- ext: ".gz",
148
- deleteOriginFile: false
149
- })
150
- );
151
- }
152
- if (compressList.includes("brotli")) {
153
- plugin.push(
154
- compression({
155
- ext: ".br",
156
- algorithm: "brotliCompress",
157
- deleteOriginFile: false
158
- })
159
- );
160
- }
161
- return plugin;
162
- }
163
-
164
- function createIcons() {
165
- return Icons({
166
- autoInstall: false
167
- });
168
- }
169
-
170
- class Ctx {
171
- options;
172
- setOptions(options) {
173
- this.options = options;
174
- }
175
- async createInfo() {
176
- console.log(
177
- boxen(
178
- `\u6B22\u8FCE\u4F7F\u7528${chalk.bold.greenBright(" \u6280\u672F\u5E95\u5EA7\u7BA1\u7406\u7CFB\u7EDF ")}
179
-
180
- ${chalk.green("\u4F7F\u7528\u6587\u6863\u5730\u5740")} ${chalk.green("\u279C")} https://134.108.39.195:9090/docs`,
181
- {
182
- padding: 1,
183
- margin: 1,
184
- align: "center",
185
- borderColor: "yellowBright",
186
- borderStyle: "round"
187
- }
188
- )
189
- );
190
- }
191
- }
192
- const ctx = new Ctx();
193
- function appInfo() {
194
- return {
195
- name: "appInfo",
196
- apply: "serve",
197
- enforce: "pre",
198
- configResolved(configuration) {
199
- const root = configuration.root;
200
- ctx.setOptions({
201
- root
202
- });
203
- },
204
- async buildStart() {
205
- ctx.createInfo();
206
- },
207
- configureServer(server) {
208
- const _printUrls = server.printUrls;
209
- server.printUrls = () => {
210
- console.log(` ${chalk.green("\u279C")} ${chalk.bold.bgBlueBright(` PUBINFO `)}${chalk.bold.bgYellowBright(` \u524D\u7AEF\u57FA\u7840\u6846\u67B6 `)}`);
211
- _printUrls();
212
- };
213
- }
214
- };
215
- }
216
-
217
- function createInspector(env) {
218
- const { VITE_APP_INSPECTOR } = env;
219
- if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") {
220
- return VueDevTools();
221
- } else {
222
- return null;
223
- }
224
- }
225
-
226
- function createLegacy(env) {
227
- if (env.VITE_BUILD_LEGACY !== "true") {
228
- return false;
229
- }
230
- return vueLegacy({
231
- modernPolyfills: [
232
- "es.array.at",
233
- "es.array.find-last"
234
- ],
235
- additionalLegacyPolyfills: ["abort-controller/polyfill"]
236
- });
237
- }
238
-
239
- function createMock(env, isBuild) {
240
- const { VITE_BUILD_MOCK } = env;
241
- if (!existsSync(resolve(cwd(), "src/mock"))) {
242
- return;
243
- }
244
- return vitePluginFakeServer({
245
- logger: !isBuild,
246
- include: "src/mock",
247
- infixName: false,
248
- enableProd: isBuild && VITE_BUILD_MOCK === "true"
249
- });
250
- }
251
-
252
- function createOpenAPI(options) {
253
- return OpenAPI(options || { enabled: false });
254
- }
255
-
256
- function createUnocss() {
257
- return Unocss();
258
- }
259
-
260
- function createVitePlugins(viteEnv, isBuild = false, config) {
261
- const vitePlugins = [
262
- vue(),
263
- vueJsx(),
264
- createLegacy(viteEnv),
265
- createAutoImport(),
266
- createComponents(),
267
- createUnocss(),
268
- createIcons(),
269
- createMock(viteEnv, isBuild),
270
- createInspector(viteEnv),
271
- createOpenAPI(config.openapi),
272
- appInfo()
273
- ];
274
- const buildPlugins = () => [
275
- ...createCompression(viteEnv)
276
- ];
277
- if (isBuild) {
278
- vitePlugins.push(...buildPlugins());
279
- }
280
- return vitePlugins.filter(Boolean);
281
- }
282
-
283
- function createDefaultAppConfig(config) {
284
- return ({ mode, command }) => {
285
- const root = cwd();
286
- const isBuild = command === "build";
287
- const timestamp = (/* @__PURE__ */ new Date()).getTime();
288
- const env = loadEnv(mode, root);
289
- const { VITE_OPEN_PROXY, VITE_BUILD_SOURCEMAP } = env;
290
- const serverProxy = getServerProxy(env, !isBuild && VITE_OPEN_PROXY === "true");
291
- const applicationConfig = {
292
- base: "./",
293
- server: {
294
- open: true,
295
- host: true,
296
- proxy: serverProxy,
297
- warmup: {
298
- clientFiles: [
299
- "./index.html"
300
- ]
301
- }
302
- },
303
- // To fix some dev problems
304
- optimizeDeps: {
305
- exclude: [
306
- "pubinfo",
307
- "@pubinfo/core",
308
- "alova"
309
- ]
310
- },
311
- resolve: {
312
- alias: alias(root)
313
- },
314
- build: {
315
- outDir: mode === "production" ? "dist" : `dist-${mode}`,
316
- sourcemap: VITE_BUILD_SOURCEMAP === "true",
317
- reportCompressedSize: false,
318
- chunkSizeWarningLimit: 2e3,
319
- rollupOptions: {
320
- output: {
321
- entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`,
322
- manualChunks: {
323
- pubinfo: ["pubinfo"]
324
- }
325
- }
326
- }
327
- },
328
- plugins: createVitePlugins(env, isBuild, config)
329
- };
330
- return applicationConfig;
331
- };
332
- }
333
-
334
- function createDefaultModuleConfig(config) {
335
- return ({ mode, command }) => {
336
- const root = cwd();
337
- const isBuild = command === "build";
338
- const env = loadEnv(mode, root);
339
- const applicationConfig = {
340
- // To fix some dev problems
341
- optimizeDeps: {
342
- exclude: [
343
- "pubinfo",
344
- "@pubinfo/core",
345
- "alova"
346
- ]
347
- },
348
- resolve: {
349
- alias: alias(root)
350
- },
351
- build: {
352
- rollupOptions: {
353
- external: [
354
- "vue",
355
- "vue-router",
356
- "pinia",
357
- "unocss"
358
- ]
359
- }
360
- },
361
- plugins: createVitePlugins(env, isBuild, config)
362
- };
363
- return applicationConfig;
364
- };
365
- }
366
-
367
- function definePubinfoConfig(config) {
368
- return {
369
- ...config,
370
- vite: mergeViteConfig(createDefaultAppConfig(config), config)
371
- };
372
- }
373
- function defineModuleConfig(config) {
374
- return {
375
- ...config,
376
- vite: mergeViteConfig(createDefaultModuleConfig(config), config)
377
- };
378
- }
379
- function mergeViteConfig(defaultOptions, config = {}) {
380
- const { vite: viteOptions = {} } = config;
381
- return defineConfig(({ mode, command }) => {
382
- return mergeConfig(
383
- defaultOptions({ mode, command }),
384
- typeof viteOptions === "function" ? viteOptions({ mode, command }) : viteOptions
385
- );
386
- });
387
- }
388
-
389
- export { defineModuleConfig, definePubinfoConfig };