@pubinfo/vite 2.0.0-rc.3 → 2.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -3
- package/dist/index.js +267 -181
- package/package.json +8 -5
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,15 @@ import { Options } from "@pubinfo/unplugin-openapi";
|
|
|
4
4
|
export * from "rolldown-vite";
|
|
5
5
|
export * from "vite-plugin-fake-server/client";
|
|
6
6
|
|
|
7
|
-
//#region src/plugins/
|
|
7
|
+
//#region src/plugins/built-in/inject-auto.d.ts
|
|
8
|
+
interface InjectAutoOptions {
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 自动注入代码
|
|
13
|
+
*/
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/plugins/built-in/lib-resolver.d.ts
|
|
8
16
|
type GlobInput = string;
|
|
9
17
|
interface ModuleEntries {
|
|
10
18
|
/**
|
|
@@ -37,6 +45,12 @@ interface PubinfoConfig {
|
|
|
37
45
|
/** `resolver` */
|
|
38
46
|
resolver?: ResolverPluginOptions;
|
|
39
47
|
}
|
|
48
|
+
interface ModuleConfig extends PubinfoConfig {
|
|
49
|
+
/**
|
|
50
|
+
* `moduleId`
|
|
51
|
+
*/
|
|
52
|
+
moduleId: InjectAutoOptions['id'];
|
|
53
|
+
}
|
|
40
54
|
//#endregion
|
|
41
55
|
//#region src/config/index.d.ts
|
|
42
56
|
/**
|
|
@@ -50,10 +64,11 @@ declare function definePubinfoConfig(config: PubinfoConfig): {
|
|
|
50
64
|
/**
|
|
51
65
|
* 构建模块配置
|
|
52
66
|
*/
|
|
53
|
-
declare function defineModuleConfig(config:
|
|
67
|
+
declare function defineModuleConfig(config: ModuleConfig): {
|
|
54
68
|
vite: UserConfigFnObject;
|
|
69
|
+
moduleId: InjectAutoOptions["id"];
|
|
55
70
|
openapi?: _pubinfo_unplugin_openapi0.Options;
|
|
56
71
|
resolver?: ResolverPluginOptions;
|
|
57
72
|
};
|
|
58
73
|
//#endregion
|
|
59
|
-
export { PubinfoConfig, ResolverPluginOptions, defineModuleConfig, definePubinfoConfig };
|
|
74
|
+
export { ModuleConfig, PubinfoConfig, ResolverPluginOptions, defineModuleConfig, definePubinfoConfig };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,18 @@ import consola from "consola";
|
|
|
6
6
|
import { dirname, join, posix, relative, resolve } from "node:path";
|
|
7
7
|
import vue from "@vitejs/plugin-vue";
|
|
8
8
|
import vueJsx from "@vitejs/plugin-vue-jsx";
|
|
9
|
+
import boxen from "boxen";
|
|
10
|
+
import fg from "fast-glob";
|
|
11
|
+
import { merge } from "lodash-es";
|
|
12
|
+
import picomatch from "picomatch";
|
|
13
|
+
import dayjs from "dayjs";
|
|
14
|
+
import { readPackageJSON } from "pkg-types";
|
|
15
|
+
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { readFile } from "node:fs/promises";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { Buffer } from "node:buffer";
|
|
19
|
+
import fse from "fs-extra/esm";
|
|
20
|
+
import JSZip from "jszip";
|
|
9
21
|
import autoImport from "unplugin-auto-import/vite";
|
|
10
22
|
import IconsResolver from "unplugin-icons/resolver";
|
|
11
23
|
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
|
|
@@ -13,19 +25,12 @@ import components from "unplugin-vue-components/vite";
|
|
|
13
25
|
import compression from "vite-plugin-compression";
|
|
14
26
|
import dts from "vite-plugin-dts";
|
|
15
27
|
import Icons from "unplugin-icons/vite";
|
|
16
|
-
import boxen from "boxen";
|
|
17
28
|
import { libInjectCss } from "vite-plugin-lib-inject-css";
|
|
18
29
|
import VueDevTools from "vite-plugin-vue-devtools";
|
|
19
30
|
import vueLegacy from "@vitejs/plugin-legacy";
|
|
20
|
-
import fg from "fast-glob";
|
|
21
|
-
import { merge } from "lodash-es";
|
|
22
|
-
import picomatch from "picomatch";
|
|
23
|
-
import { existsSync } from "node:fs";
|
|
24
31
|
import { vitePluginFakeServer } from "vite-plugin-fake-server";
|
|
25
32
|
import OpenAPI from "@pubinfo/unplugin-openapi/vite";
|
|
26
33
|
import Unocss from "unocss/vite";
|
|
27
|
-
import { readFile } from "node:fs/promises";
|
|
28
|
-
import { fileURLToPath } from "node:url";
|
|
29
34
|
|
|
30
35
|
export * from "rolldown-vite"
|
|
31
36
|
|
|
@@ -68,106 +73,15 @@ function getServerProxy(env, isProxy) {
|
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
//#endregion
|
|
71
|
-
//#region src/plugins/
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
...autoImport({
|
|
75
|
-
imports: [
|
|
76
|
-
"vue",
|
|
77
|
-
"vue-router",
|
|
78
|
-
"pinia",
|
|
79
|
-
{ pubinfo: ["useAuth"] }
|
|
80
|
-
],
|
|
81
|
-
ignore: ["h"],
|
|
82
|
-
dts: "./.pubinfo/auto-imports.d.ts",
|
|
83
|
-
resolvers: [AntDesignVueResolver(), IconsResolver({ prefix: "i" })]
|
|
84
|
-
}),
|
|
85
|
-
enforce: "pre"
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/plugins/components.ts
|
|
91
|
-
function createComponents() {
|
|
92
|
-
return components({
|
|
93
|
-
dirs: ["src/components"],
|
|
94
|
-
directives: true,
|
|
95
|
-
include: [
|
|
96
|
-
/\.vue$/,
|
|
97
|
-
/\.vue\?vue/,
|
|
98
|
-
/\.tsx$/
|
|
99
|
-
],
|
|
100
|
-
resolvers: [
|
|
101
|
-
IconsResolver(),
|
|
102
|
-
AntDesignVueResolver({
|
|
103
|
-
resolveIcons: true,
|
|
104
|
-
importStyle: false
|
|
105
|
-
}),
|
|
106
|
-
{
|
|
107
|
-
type: "component",
|
|
108
|
-
resolve(name) {
|
|
109
|
-
const components$1 = [
|
|
110
|
-
"PubinfoApp",
|
|
111
|
-
"PubinfoProvider",
|
|
112
|
-
"PubinfoIcon"
|
|
113
|
-
];
|
|
114
|
-
if (components$1.includes(name)) return {
|
|
115
|
-
name,
|
|
116
|
-
from: "pubinfo"
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
],
|
|
121
|
-
dts: "./.pubinfo/components.d.ts"
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region src/plugins/compression.ts
|
|
127
|
-
function createCompression(env) {
|
|
128
|
-
const { VITE_BUILD_COMPRESS } = env;
|
|
129
|
-
const compressList = VITE_BUILD_COMPRESS?.split(",") ?? [];
|
|
130
|
-
const plugin = [];
|
|
131
|
-
if (compressList.includes("gzip")) plugin.push(compression({
|
|
132
|
-
ext: ".gz",
|
|
133
|
-
deleteOriginFile: false
|
|
134
|
-
}));
|
|
135
|
-
if (compressList.includes("brotli")) plugin.push(compression({
|
|
136
|
-
ext: ".br",
|
|
137
|
-
algorithm: "brotliCompress",
|
|
138
|
-
deleteOriginFile: false
|
|
139
|
-
}));
|
|
140
|
-
return plugin;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
//#endregion
|
|
144
|
-
//#region src/plugins/dts.ts
|
|
145
|
-
function createDTS() {
|
|
146
|
-
return {
|
|
147
|
-
...dts({
|
|
148
|
-
clearPureImport: false,
|
|
149
|
-
exclude: ["tests/**/*"]
|
|
150
|
-
}),
|
|
151
|
-
enforce: "post"
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region src/plugins/icon.ts
|
|
157
|
-
function createIcons() {
|
|
158
|
-
return Icons({ autoInstall: false });
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
//#endregion
|
|
162
|
-
//#region src/plugins/info.ts
|
|
163
|
-
var Ctx = class {
|
|
76
|
+
//#region src/plugins/built-in/info.ts
|
|
77
|
+
var Ctx$1 = class {
|
|
164
78
|
options;
|
|
165
79
|
setOptions(options) {
|
|
166
80
|
this.options = options;
|
|
167
81
|
}
|
|
168
82
|
async createInfo() {
|
|
169
83
|
console.log(boxen(`\
|
|
170
|
-
欢迎使用${chalk.bold.greenBright("
|
|
84
|
+
欢迎使用${chalk.bold.greenBright(" 产数研发底座系统 ")}\n
|
|
171
85
|
${chalk.green("使用文档地址")} ${chalk.green("➜")} https://134.108.39.195:9090/docs`, {
|
|
172
86
|
padding: 1,
|
|
173
87
|
margin: 1,
|
|
@@ -177,18 +91,18 @@ ${chalk.green("使用文档地址")} ${chalk.green("➜")} https://134.108.39.19
|
|
|
177
91
|
}));
|
|
178
92
|
}
|
|
179
93
|
};
|
|
180
|
-
const ctx = new Ctx();
|
|
181
|
-
function
|
|
94
|
+
const ctx$1 = new Ctx$1();
|
|
95
|
+
function createAppInfo() {
|
|
182
96
|
return {
|
|
183
|
-
name: "
|
|
97
|
+
name: "createAppInfo",
|
|
184
98
|
apply: "serve",
|
|
185
99
|
enforce: "pre",
|
|
186
100
|
configResolved(configuration) {
|
|
187
101
|
const root = configuration.root;
|
|
188
|
-
ctx.setOptions({ root });
|
|
102
|
+
ctx$1.setOptions({ root });
|
|
189
103
|
},
|
|
190
104
|
async buildStart() {
|
|
191
|
-
ctx.createInfo();
|
|
105
|
+
ctx$1.createInfo();
|
|
192
106
|
},
|
|
193
107
|
configureServer(server) {
|
|
194
108
|
const _printUrls = server.printUrls;
|
|
@@ -201,31 +115,40 @@ function appInfo() {
|
|
|
201
115
|
}
|
|
202
116
|
|
|
203
117
|
//#endregion
|
|
204
|
-
//#region src/plugins/inject-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
118
|
+
//#region src/plugins/built-in/inject-auto.ts
|
|
119
|
+
/**
|
|
120
|
+
* 自动注入代码
|
|
121
|
+
*/
|
|
122
|
+
function createInjectAuto(options) {
|
|
123
|
+
const { id } = options;
|
|
124
|
+
let entryFiles = [];
|
|
125
|
+
return {
|
|
126
|
+
name: "vite-plugin-inject-auto",
|
|
127
|
+
enforce: "pre",
|
|
128
|
+
configResolved(config) {
|
|
129
|
+
const lib = config.build?.lib;
|
|
130
|
+
if (!lib || !lib.entry) return;
|
|
131
|
+
const toAbs = (p) => resolve(config.root, p);
|
|
132
|
+
if (typeof lib.entry === "string") entryFiles = [toAbs(lib.entry)];
|
|
133
|
+
else if (Array.isArray(lib.entry)) entryFiles = lib.entry.map(toAbs);
|
|
134
|
+
else if (typeof lib.entry === "object") entryFiles = Object.values(lib.entry).map(toAbs);
|
|
135
|
+
},
|
|
136
|
+
transform(code, _id) {
|
|
137
|
+
if (entryFiles.includes(_id)) return `
|
|
138
|
+
import { defineRouteModule, defineIconModule } from 'pubinfo';
|
|
139
|
+
import modules from 'virtual:pubinfo-resolver';
|
|
208
140
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
function createInspector(env) {
|
|
212
|
-
const { VITE_APP_INSPECTOR } = env;
|
|
213
|
-
if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") return VueDevTools();
|
|
214
|
-
else return null;
|
|
215
|
-
}
|
|
141
|
+
defineRouteModule('${id}', modules.pages);
|
|
142
|
+
defineIconModule('${id}', modules.icons);
|
|
216
143
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return vueLegacy({
|
|
222
|
-
modernPolyfills: ["es.array.at", "es.array.find-last"],
|
|
223
|
-
additionalLegacyPolyfills: ["abort-controller/polyfill"]
|
|
224
|
-
});
|
|
144
|
+
${code}
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
225
148
|
}
|
|
226
149
|
|
|
227
150
|
//#endregion
|
|
228
|
-
//#region src/plugins/lib-resolver.ts
|
|
151
|
+
//#region src/plugins/built-in/lib-resolver.ts
|
|
229
152
|
function getPatternBase(pattern) {
|
|
230
153
|
const parts = pattern.split("/");
|
|
231
154
|
const baseParts = [];
|
|
@@ -258,14 +181,9 @@ function libResolverPlugin(options) {
|
|
|
258
181
|
const normalizedFile = normalizePath$1(file);
|
|
259
182
|
const isVueOrTsFile = /\.(vue|tsx?|jsx?)$/.test(normalizedFile);
|
|
260
183
|
const relativePath = serverRoot ? normalizePath$1(relative(serverRoot, normalizedFile)) : normalizedFile;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const matches = matcher(relativePath);
|
|
265
|
-
return matches;
|
|
266
|
-
});
|
|
267
|
-
const result = matchesPattern && isVueOrTsFile;
|
|
268
|
-
return result;
|
|
184
|
+
return Object.values(options.entries).some((pattern, index) => {
|
|
185
|
+
return picomatch(pattern)(relativePath);
|
|
186
|
+
}) && isVueOrTsFile;
|
|
269
187
|
}
|
|
270
188
|
return {
|
|
271
189
|
name: "vite-plugin-lib-resolver",
|
|
@@ -299,7 +217,7 @@ function libResolverPlugin(options) {
|
|
|
299
217
|
},
|
|
300
218
|
async load(id) {
|
|
301
219
|
if (id !== resolvedId) return null;
|
|
302
|
-
|
|
220
|
+
return `export default {\n ${(await Promise.all(Object.entries(options.entries).map(async ([key, pattern]) => {
|
|
303
221
|
try {
|
|
304
222
|
const files = await fg(pattern, { absolute: true });
|
|
305
223
|
if (files.length === 0) return {
|
|
@@ -311,8 +229,7 @@ function libResolverPlugin(options) {
|
|
|
311
229
|
const imports = files.map((file) => {
|
|
312
230
|
const absPath = normalizePath$1(file);
|
|
313
231
|
const relToBase = normalizePath$1(relative(resolve(base), file));
|
|
314
|
-
|
|
315
|
-
return `"${relPath}": () => import("${absPath}")`;
|
|
232
|
+
return `"${posix.join(base, relToBase)}": () => import("${absPath}")`;
|
|
316
233
|
}).join(",\n");
|
|
317
234
|
return {
|
|
318
235
|
key,
|
|
@@ -327,10 +244,7 @@ function libResolverPlugin(options) {
|
|
|
327
244
|
files: []
|
|
328
245
|
};
|
|
329
246
|
}
|
|
330
|
-
}))
|
|
331
|
-
const moduleDefs = moduleResults.map((result) => result.content);
|
|
332
|
-
const content = `export default {\n ${moduleDefs.join(",\n ")}\n}`;
|
|
333
|
-
return content;
|
|
247
|
+
}))).map((result) => result.content).join(",\n ")}\n}`;
|
|
334
248
|
}
|
|
335
249
|
};
|
|
336
250
|
}
|
|
@@ -343,35 +257,26 @@ function createLibResolver(options) {
|
|
|
343
257
|
}
|
|
344
258
|
|
|
345
259
|
//#endregion
|
|
346
|
-
//#region src/plugins/
|
|
347
|
-
function
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
function createOpenAPI(options) {
|
|
361
|
-
return OpenAPI(options || { enabled: false });
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
//#endregion
|
|
365
|
-
//#region src/plugins/unocss.ts
|
|
366
|
-
function createUnocss() {
|
|
367
|
-
return Unocss();
|
|
260
|
+
//#region src/plugins/built-in/system-info.ts
|
|
261
|
+
function createSystemInfo(options = {}) {
|
|
262
|
+
const defineKey = options.defineKey || "__SYSTEM_INFO__";
|
|
263
|
+
return {
|
|
264
|
+
name: "vite-plugin-system-info",
|
|
265
|
+
async config() {
|
|
266
|
+
const pkg = await readPackageJSON();
|
|
267
|
+
const systemInfo = {
|
|
268
|
+
buildTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
|
269
|
+
pkg
|
|
270
|
+
};
|
|
271
|
+
return { define: { [defineKey]: JSON.stringify(systemInfo) } };
|
|
272
|
+
}
|
|
273
|
+
};
|
|
368
274
|
}
|
|
369
275
|
|
|
370
276
|
//#endregion
|
|
371
|
-
//#region src/plugins/virtual-inspector.ts
|
|
277
|
+
//#region src/plugins/built-in/virtual-inspector.ts
|
|
372
278
|
function getInspectorPath() {
|
|
373
|
-
|
|
374
|
-
return pluginPath;
|
|
279
|
+
return normalizePath(dirname(fileURLToPath(import.meta.url)));
|
|
375
280
|
}
|
|
376
281
|
function createVirtualInspectorPlugin(options = {}) {
|
|
377
282
|
const { enabled = true } = options;
|
|
@@ -395,10 +300,7 @@ function createVirtualInspectorPlugin(options = {}) {
|
|
|
395
300
|
});
|
|
396
301
|
},
|
|
397
302
|
async resolveId(importee) {
|
|
398
|
-
if (importee === virtualModuleId)
|
|
399
|
-
const resolved = resolve(inspectorPath, "load.js");
|
|
400
|
-
return resolved;
|
|
401
|
-
}
|
|
303
|
+
if (importee === virtualModuleId) return resolve(inspectorPath, "load.js");
|
|
402
304
|
return null;
|
|
403
305
|
},
|
|
404
306
|
async load(id) {
|
|
@@ -436,10 +338,193 @@ function createVirtualInspector(options) {
|
|
|
436
338
|
return createVirtualInspectorPlugin(options);
|
|
437
339
|
}
|
|
438
340
|
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/plugins/built-in/zip.ts
|
|
343
|
+
var Ctx = class {
|
|
344
|
+
root;
|
|
345
|
+
outDirName;
|
|
346
|
+
dir;
|
|
347
|
+
outDir;
|
|
348
|
+
setOptions(options) {
|
|
349
|
+
this.root = options.root;
|
|
350
|
+
this.outDirName = options.outDirName;
|
|
351
|
+
this.getDirPath();
|
|
352
|
+
}
|
|
353
|
+
getDirPath() {
|
|
354
|
+
const dir = resolve(this.root, this.outDirName);
|
|
355
|
+
const outDir = `${dir}.zip`;
|
|
356
|
+
this.dir = dir;
|
|
357
|
+
this.outDir = outDir;
|
|
358
|
+
}
|
|
359
|
+
async clean() {
|
|
360
|
+
if (await fse.pathExists(this.outDir)) fse.remove(this.outDir);
|
|
361
|
+
}
|
|
362
|
+
async compress() {
|
|
363
|
+
const zip = new JSZip();
|
|
364
|
+
const files = this.getAllFiles(this.dir);
|
|
365
|
+
if (files && Array.isArray(files) && files.length) files.forEach((file) => {
|
|
366
|
+
const fileData = readFileSync(file, { encoding: "binary" });
|
|
367
|
+
zip.file(relative(this.dir, file), fileData, { binary: true });
|
|
368
|
+
});
|
|
369
|
+
const content = await zip.generateAsync({ type: "arraybuffer" });
|
|
370
|
+
writeFileSync(this.outDir, Buffer.from(content));
|
|
371
|
+
}
|
|
372
|
+
getAllFiles(dirPath) {
|
|
373
|
+
const files = readdirSync(dirPath);
|
|
374
|
+
const result = [];
|
|
375
|
+
for (const file of files) {
|
|
376
|
+
const filePath = join(dirPath, file);
|
|
377
|
+
if (statSync(filePath).isDirectory()) result.push(...this.getAllFiles(filePath));
|
|
378
|
+
else result.push(filePath);
|
|
379
|
+
}
|
|
380
|
+
return result;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
const ctx = new Ctx();
|
|
384
|
+
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/plugins/intergrations/auto-import.ts
|
|
387
|
+
function createAutoImport() {
|
|
388
|
+
return {
|
|
389
|
+
...autoImport({
|
|
390
|
+
imports: [
|
|
391
|
+
"vue",
|
|
392
|
+
"vue-router",
|
|
393
|
+
"pinia",
|
|
394
|
+
{ pubinfo: ["useAuth"] }
|
|
395
|
+
],
|
|
396
|
+
ignore: ["h"],
|
|
397
|
+
dts: "./.pubinfo/auto-imports.d.ts",
|
|
398
|
+
resolvers: [AntDesignVueResolver(), IconsResolver({ prefix: "i" })]
|
|
399
|
+
}),
|
|
400
|
+
enforce: "pre"
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/plugins/intergrations/components.ts
|
|
406
|
+
function createComponents() {
|
|
407
|
+
return components({
|
|
408
|
+
dirs: ["src/components"],
|
|
409
|
+
directives: true,
|
|
410
|
+
include: [
|
|
411
|
+
/\.vue$/,
|
|
412
|
+
/\.vue\?vue/,
|
|
413
|
+
/\.tsx$/
|
|
414
|
+
],
|
|
415
|
+
resolvers: [
|
|
416
|
+
IconsResolver(),
|
|
417
|
+
AntDesignVueResolver({
|
|
418
|
+
resolveIcons: true,
|
|
419
|
+
importStyle: false
|
|
420
|
+
}),
|
|
421
|
+
{
|
|
422
|
+
type: "component",
|
|
423
|
+
resolve(name) {
|
|
424
|
+
if ([
|
|
425
|
+
"PubinfoApp",
|
|
426
|
+
"PubinfoProvider",
|
|
427
|
+
"PubinfoIcon"
|
|
428
|
+
].includes(name)) return {
|
|
429
|
+
name,
|
|
430
|
+
from: "pubinfo"
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
],
|
|
435
|
+
dts: "./.pubinfo/components.d.ts"
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/plugins/intergrations/compression.ts
|
|
441
|
+
function createCompression(env) {
|
|
442
|
+
const { VITE_BUILD_COMPRESS } = env;
|
|
443
|
+
const compressList = VITE_BUILD_COMPRESS?.split(",") ?? [];
|
|
444
|
+
const plugin = [];
|
|
445
|
+
if (compressList.includes("gzip")) plugin.push(compression({
|
|
446
|
+
ext: ".gz",
|
|
447
|
+
deleteOriginFile: false
|
|
448
|
+
}));
|
|
449
|
+
if (compressList.includes("brotli")) plugin.push(compression({
|
|
450
|
+
ext: ".br",
|
|
451
|
+
algorithm: "brotliCompress",
|
|
452
|
+
deleteOriginFile: false
|
|
453
|
+
}));
|
|
454
|
+
return plugin;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/plugins/intergrations/dts.ts
|
|
459
|
+
function createDTS() {
|
|
460
|
+
return {
|
|
461
|
+
...dts({
|
|
462
|
+
clearPureImport: false,
|
|
463
|
+
exclude: ["tests/**/*"]
|
|
464
|
+
}),
|
|
465
|
+
enforce: "post"
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/plugins/intergrations/icon.ts
|
|
471
|
+
function createIcons() {
|
|
472
|
+
return Icons({ autoInstall: false });
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/plugins/intergrations/inject-css.ts
|
|
477
|
+
function createInjectCSS() {
|
|
478
|
+
return libInjectCss();
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/plugins/intergrations/inspector.ts
|
|
483
|
+
function createInspector(env) {
|
|
484
|
+
const { VITE_APP_INSPECTOR } = env;
|
|
485
|
+
if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") return VueDevTools();
|
|
486
|
+
else return null;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/plugins/intergrations/legacy.ts
|
|
491
|
+
function createLegacy(env) {
|
|
492
|
+
if (env.VITE_BUILD_LEGACY !== "true") return false;
|
|
493
|
+
return vueLegacy({
|
|
494
|
+
modernPolyfills: ["es.array.at", "es.array.find-last"],
|
|
495
|
+
additionalLegacyPolyfills: ["abort-controller/polyfill"]
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region src/plugins/intergrations/mock.ts
|
|
501
|
+
function createMock(env, isBuild) {
|
|
502
|
+
const { VITE_BUILD_MOCK } = env;
|
|
503
|
+
if (!existsSync(resolve(cwd(), "src/mock"))) return;
|
|
504
|
+
return vitePluginFakeServer({
|
|
505
|
+
logger: !isBuild,
|
|
506
|
+
include: "src/mock",
|
|
507
|
+
infixName: false,
|
|
508
|
+
enableProd: isBuild && VITE_BUILD_MOCK === "true"
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/plugins/intergrations/openapi.ts
|
|
514
|
+
function createOpenAPI(options) {
|
|
515
|
+
return OpenAPI(options || { enabled: false });
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/plugins/intergrations/unocss.ts
|
|
520
|
+
function createUnocss() {
|
|
521
|
+
return Unocss();
|
|
522
|
+
}
|
|
523
|
+
|
|
439
524
|
//#endregion
|
|
440
525
|
//#region src/plugins/index.ts
|
|
441
526
|
function createVitePlugins(viteEnv, isBuild = false, config, type) {
|
|
442
|
-
|
|
527
|
+
return [
|
|
443
528
|
vue(),
|
|
444
529
|
vueJsx(),
|
|
445
530
|
createLegacy(viteEnv),
|
|
@@ -451,12 +536,16 @@ function createVitePlugins(viteEnv, isBuild = false, config, type) {
|
|
|
451
536
|
createInspector(viteEnv),
|
|
452
537
|
createOpenAPI(config.openapi),
|
|
453
538
|
createLibResolver(config.resolver),
|
|
454
|
-
|
|
539
|
+
createAppInfo(),
|
|
455
540
|
createVirtualInspector({ enabled: true }),
|
|
456
|
-
|
|
541
|
+
createSystemInfo(),
|
|
542
|
+
type === "module" ? [
|
|
543
|
+
createDTS(),
|
|
544
|
+
createInjectCSS(),
|
|
545
|
+
createInjectAuto({ id: config.moduleId })
|
|
546
|
+
] : null,
|
|
457
547
|
isBuild ? createCompression(viteEnv) : null
|
|
458
|
-
];
|
|
459
|
-
return vitePlugins.filter(Boolean);
|
|
548
|
+
].filter(Boolean);
|
|
460
549
|
}
|
|
461
550
|
|
|
462
551
|
//#endregion
|
|
@@ -468,13 +557,12 @@ function createDefaultAppConfig(config) {
|
|
|
468
557
|
const timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
469
558
|
const env = loadEnv(mode, root);
|
|
470
559
|
const { VITE_OPEN_PROXY, VITE_BUILD_SOURCEMAP } = env;
|
|
471
|
-
|
|
472
|
-
const applicationConfig = {
|
|
560
|
+
return {
|
|
473
561
|
base: "./",
|
|
474
562
|
server: {
|
|
475
563
|
open: true,
|
|
476
564
|
host: true,
|
|
477
|
-
proxy:
|
|
565
|
+
proxy: getServerProxy(env, !isBuild && VITE_OPEN_PROXY === "true"),
|
|
478
566
|
warmup: { clientFiles: ["./index.html"] }
|
|
479
567
|
},
|
|
480
568
|
optimizeDeps: { exclude: [
|
|
@@ -498,7 +586,6 @@ function createDefaultAppConfig(config) {
|
|
|
498
586
|
},
|
|
499
587
|
plugins: createVitePlugins(env, isBuild, config, "app")
|
|
500
588
|
};
|
|
501
|
-
return applicationConfig;
|
|
502
589
|
};
|
|
503
590
|
}
|
|
504
591
|
|
|
@@ -509,7 +596,7 @@ function createDefaultModuleConfig(config) {
|
|
|
509
596
|
const root = cwd();
|
|
510
597
|
const isBuild = command === "build";
|
|
511
598
|
const env = loadEnv(mode, root);
|
|
512
|
-
|
|
599
|
+
return {
|
|
513
600
|
optimizeDeps: { exclude: [
|
|
514
601
|
"pubinfo",
|
|
515
602
|
"@pubinfo/core",
|
|
@@ -527,7 +614,6 @@ function createDefaultModuleConfig(config) {
|
|
|
527
614
|
} },
|
|
528
615
|
plugins: createVitePlugins(env, isBuild, config, "module")
|
|
529
616
|
};
|
|
530
|
-
return applicationConfig;
|
|
531
617
|
};
|
|
532
618
|
}
|
|
533
619
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubinfo/vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-rc.
|
|
4
|
+
"version": "2.0.0-rc.5",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
19
|
+
},
|
|
17
20
|
"peerDependencies": {
|
|
18
|
-
"vue": "^3.5.17"
|
|
19
|
-
"vue-i18n": "^10.0.7"
|
|
21
|
+
"vue": "^3.5.17"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
22
24
|
"@pubinfo/unplugin-openapi": "^0.9.0",
|
|
@@ -28,11 +30,13 @@
|
|
|
28
30
|
"chalk": "^5.4.1",
|
|
29
31
|
"chokidar": "^4.0.1",
|
|
30
32
|
"consola": "^3.4.2",
|
|
33
|
+
"dayjs": "^1.11.13",
|
|
31
34
|
"fast-glob": "^3.3.3",
|
|
32
35
|
"fs-extra": "^11.3.0",
|
|
33
36
|
"jszip": "^3.10.1",
|
|
34
37
|
"lodash-es": "^4.17.21",
|
|
35
38
|
"picomatch": "^4.0.3",
|
|
39
|
+
"pkg-types": "^2.3.0",
|
|
36
40
|
"rolldown-vite": "^7.1.2",
|
|
37
41
|
"terser": "^5.43.1",
|
|
38
42
|
"unocss": "^66.4.2",
|
|
@@ -51,8 +55,7 @@
|
|
|
51
55
|
"@types/lodash-es": "^4.17.12",
|
|
52
56
|
"@types/node": "^24.0.10",
|
|
53
57
|
"@types/picomatch": "^4.0.2",
|
|
54
|
-
"vue": "^3.5.17"
|
|
55
|
-
"vue-i18n": "^10.0.7"
|
|
58
|
+
"vue": "^3.5.17"
|
|
56
59
|
},
|
|
57
60
|
"scripts": {
|
|
58
61
|
"dev": "tsdown --watch",
|