@pubinfo/vite 0.6.3
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.mts +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +623 -0
- package/package.json +63 -0
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
/// <reference types="@intlify/unplugin-vue-i18n/messages" />
|
|
3
|
+
/// <reference types="unplugin-icons/types/vue" />
|
|
4
|
+
/// <reference types="vite-plugin-vue-meta-layouts/client" />
|
|
5
|
+
|
|
6
|
+
import * as vite from 'vite';
|
|
7
|
+
import { UserConfig } from 'vite';
|
|
8
|
+
|
|
9
|
+
declare function defineConfig(defineOptions?: UserConfig): vite.UserConfigExport;
|
|
10
|
+
|
|
11
|
+
export { defineConfig };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import path, { resolve as resolve$1, relative, join } from 'node:path';
|
|
3
|
+
import { defineConfig as defineConfig$1, loadEnv, mergeConfig } from 'vite';
|
|
4
|
+
import vue from '@vitejs/plugin-vue';
|
|
5
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
6
|
+
import vueLegacy from '@vitejs/plugin-legacy';
|
|
7
|
+
import autoImport from 'unplugin-auto-import/vite';
|
|
8
|
+
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
|
|
9
|
+
import IconsResolver from 'unplugin-icons/resolver';
|
|
10
|
+
import components from 'unplugin-vue-components/vite';
|
|
11
|
+
import Unocss from 'unocss/vite';
|
|
12
|
+
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
|
13
|
+
import vueI18n from '@intlify/unplugin-vue-i18n/vite';
|
|
14
|
+
import { vitePluginFakeServer } from 'vite-plugin-fake-server';
|
|
15
|
+
import Layouts from 'vite-plugin-vue-meta-layouts';
|
|
16
|
+
import compression from 'vite-plugin-compression';
|
|
17
|
+
import banner from 'vite-plugin-banner';
|
|
18
|
+
import dayjs from 'dayjs';
|
|
19
|
+
import fg from 'fast-glob';
|
|
20
|
+
import { Buffer } from 'node:buffer';
|
|
21
|
+
import { readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs';
|
|
22
|
+
import JSZip from 'jszip';
|
|
23
|
+
import fse from 'fs-extra/esm';
|
|
24
|
+
import consola$1, { consola } from 'consola';
|
|
25
|
+
import Icons from 'unplugin-icons/vite';
|
|
26
|
+
import TurboConsole from 'unplugin-turbo-console/vite';
|
|
27
|
+
import VueDevTools from 'vite-plugin-vue-devtools';
|
|
28
|
+
import OpenAPI from '@pubinfo/unplugin-openapi/vite';
|
|
29
|
+
import EnvRuntime from 'vite-plugin-env-runtime';
|
|
30
|
+
import boxen from 'boxen';
|
|
31
|
+
import chalk from 'chalk';
|
|
32
|
+
import { readPackageJSON } from 'pkg-types';
|
|
33
|
+
import fs from 'node:fs/promises';
|
|
34
|
+
|
|
35
|
+
function resolve(name) {
|
|
36
|
+
if (!name.startsWith("usePub")) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
name,
|
|
41
|
+
from: "@pubinfo/composables"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function PubInfoResolver$1() {
|
|
45
|
+
return (name) => {
|
|
46
|
+
return resolve(name);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function createAutoImport() {
|
|
51
|
+
return autoImport({
|
|
52
|
+
imports: [
|
|
53
|
+
"vue",
|
|
54
|
+
"vue-router",
|
|
55
|
+
"vue-i18n",
|
|
56
|
+
"vitest",
|
|
57
|
+
{
|
|
58
|
+
alova: [
|
|
59
|
+
"useRequest",
|
|
60
|
+
"invalidateCache"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
dts: "./types/auto-imports.d.ts",
|
|
65
|
+
dirs: [
|
|
66
|
+
"./src/utils/composables/**",
|
|
67
|
+
"./src/composables/**/*",
|
|
68
|
+
"./src/api/modules/**/*.ts"
|
|
69
|
+
],
|
|
70
|
+
resolvers: [
|
|
71
|
+
AntDesignVueResolver(),
|
|
72
|
+
IconsResolver({
|
|
73
|
+
prefix: "i"
|
|
74
|
+
}),
|
|
75
|
+
PubInfoResolver$1()
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function resolveComponent(componentName) {
|
|
81
|
+
if (!componentName.match(/^Pub[A-Z]/)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
name: componentName,
|
|
86
|
+
as: componentName,
|
|
87
|
+
from: "@pubinfo/components"
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function resolveDirective(directiveName) {
|
|
91
|
+
if (!directiveName.match(/^Pub[A-Z]/)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
name: directiveName,
|
|
96
|
+
from: "@pubinfo/directives"
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function PubInfoResolver() {
|
|
100
|
+
return [
|
|
101
|
+
{
|
|
102
|
+
type: "component",
|
|
103
|
+
resolve: async (name) => {
|
|
104
|
+
return resolveComponent(name);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: "directive",
|
|
109
|
+
resolve: async (name) => {
|
|
110
|
+
return resolveDirective(name);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function createComponents() {
|
|
117
|
+
return components({
|
|
118
|
+
dirs: [
|
|
119
|
+
"src/components",
|
|
120
|
+
"src/layouts/ui-kit"
|
|
121
|
+
],
|
|
122
|
+
directives: true,
|
|
123
|
+
include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
|
|
124
|
+
resolvers: [
|
|
125
|
+
IconsResolver(),
|
|
126
|
+
AntDesignVueResolver({
|
|
127
|
+
resolveIcons: true,
|
|
128
|
+
importStyle: false
|
|
129
|
+
}),
|
|
130
|
+
PubInfoResolver()
|
|
131
|
+
],
|
|
132
|
+
dts: "./types/components.d.ts"
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function createUnocss() {
|
|
137
|
+
return Unocss();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function createSvgIcon(isBuild) {
|
|
141
|
+
return createSvgIconsPlugin({
|
|
142
|
+
iconDirs: [path.resolve(process.cwd(), "src/assets/icons/")],
|
|
143
|
+
symbolId: "icon-[dir]-[name]",
|
|
144
|
+
svgoOptions: isBuild
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function createI18n() {
|
|
149
|
+
const root = process.cwd();
|
|
150
|
+
const pathResolve = (pathname) => resolve$1(root, ".", pathname);
|
|
151
|
+
return vueI18n({
|
|
152
|
+
include: `${pathResolve("src")}/locales/lang/**`
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function createMock(env, isBuild) {
|
|
157
|
+
const { VITE_BUILD_MOCK } = env;
|
|
158
|
+
return vitePluginFakeServer({
|
|
159
|
+
logger: !isBuild,
|
|
160
|
+
include: "src/mock",
|
|
161
|
+
infixName: false,
|
|
162
|
+
enableProd: isBuild && VITE_BUILD_MOCK === "true"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function createLayouts() {
|
|
167
|
+
return Layouts({
|
|
168
|
+
defaultLayout: "index"
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function createCompression(env) {
|
|
173
|
+
const { VITE_BUILD_COMPRESS } = env;
|
|
174
|
+
const compressList = VITE_BUILD_COMPRESS.split(",");
|
|
175
|
+
const plugin = [];
|
|
176
|
+
if (compressList.includes("gzip")) {
|
|
177
|
+
plugin.push(
|
|
178
|
+
compression({
|
|
179
|
+
ext: ".gz",
|
|
180
|
+
deleteOriginFile: false
|
|
181
|
+
})
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (compressList.includes("brotli")) {
|
|
185
|
+
plugin.push(
|
|
186
|
+
compression({
|
|
187
|
+
ext: ".br",
|
|
188
|
+
algorithm: "brotliCompress",
|
|
189
|
+
deleteOriginFile: false
|
|
190
|
+
})
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return plugin;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const deploymentTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
197
|
+
function createBanner() {
|
|
198
|
+
return banner(`
|
|
199
|
+
/**
|
|
200
|
+
* \u7531 \u793E\u4F1A\u6CBB\u7406\u4E8B\u4E1A\u90E8 \u63D0\u4F9B\u6280\u672F\u652F\u6301
|
|
201
|
+
* Powered by wsy-admin
|
|
202
|
+
* ${deploymentTime}
|
|
203
|
+
*/
|
|
204
|
+
`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
var __defProp$2 = Object.defineProperty;
|
|
208
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
209
|
+
var __publicField$2 = (obj, key, value) => {
|
|
210
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
211
|
+
return value;
|
|
212
|
+
};
|
|
213
|
+
let Ctx$2 = class Ctx {
|
|
214
|
+
constructor(options) {
|
|
215
|
+
__publicField$2(this, "root");
|
|
216
|
+
__publicField$2(this, "globs");
|
|
217
|
+
__publicField$2(this, "sourcePath");
|
|
218
|
+
__publicField$2(this, "path");
|
|
219
|
+
this.globs = options.globs;
|
|
220
|
+
}
|
|
221
|
+
setRoot(root) {
|
|
222
|
+
this.root = root;
|
|
223
|
+
}
|
|
224
|
+
searchGlob() {
|
|
225
|
+
const { root, globs } = this;
|
|
226
|
+
this.sourcePath = fg.sync(globs, {
|
|
227
|
+
cwd: root,
|
|
228
|
+
onlyFiles: true
|
|
229
|
+
});
|
|
230
|
+
this.normalizePath();
|
|
231
|
+
}
|
|
232
|
+
normalizePath() {
|
|
233
|
+
const path = [];
|
|
234
|
+
for (const f of this.sourcePath) {
|
|
235
|
+
path.push(`@use "${f}" as *;`);
|
|
236
|
+
}
|
|
237
|
+
this.path = path.join("");
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
function scssPreprocessor(options) {
|
|
241
|
+
const ctx = new Ctx$2(options);
|
|
242
|
+
return {
|
|
243
|
+
name: "vite-plugin-scssPreprocessor",
|
|
244
|
+
enforce: "pre",
|
|
245
|
+
config: (config) => {
|
|
246
|
+
ctx.setRoot(config.root);
|
|
247
|
+
ctx.searchGlob();
|
|
248
|
+
return {
|
|
249
|
+
css: {
|
|
250
|
+
preprocessorOptions: {
|
|
251
|
+
scss: {
|
|
252
|
+
additionalData: ctx.path
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function createPreprocessor() {
|
|
261
|
+
return scssPreprocessor({
|
|
262
|
+
globs: ["src/assets/styles/resources/*.scss"]
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
var __defProp$1 = Object.defineProperty;
|
|
267
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
268
|
+
var __publicField$1 = (obj, key, value) => {
|
|
269
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
270
|
+
return value;
|
|
271
|
+
};
|
|
272
|
+
let Ctx$1 = class Ctx {
|
|
273
|
+
constructor() {
|
|
274
|
+
__publicField$1(this, "root");
|
|
275
|
+
__publicField$1(this, "outDirName");
|
|
276
|
+
__publicField$1(this, "dir");
|
|
277
|
+
__publicField$1(this, "outDir");
|
|
278
|
+
}
|
|
279
|
+
setOptions(options) {
|
|
280
|
+
this.root = options.root;
|
|
281
|
+
this.outDirName = options.outDirName;
|
|
282
|
+
this.getDirPath();
|
|
283
|
+
}
|
|
284
|
+
getDirPath() {
|
|
285
|
+
const dir = resolve$1(this.root, this.outDirName);
|
|
286
|
+
const outDir = `${dir}.zip`;
|
|
287
|
+
this.dir = dir;
|
|
288
|
+
this.outDir = outDir;
|
|
289
|
+
}
|
|
290
|
+
async clean() {
|
|
291
|
+
const pathExists = await fse.pathExists(this.outDir);
|
|
292
|
+
if (pathExists) {
|
|
293
|
+
fse.remove(this.outDir);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async compress() {
|
|
297
|
+
const zip = new JSZip();
|
|
298
|
+
const files = this.getAllFiles(this.dir);
|
|
299
|
+
if (files && Array.isArray(files) && files.length) {
|
|
300
|
+
files.forEach((file) => {
|
|
301
|
+
const fileData = readFileSync(file, { encoding: "binary" });
|
|
302
|
+
zip.file(relative(this.dir, file), fileData, { binary: true });
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
const content = await zip.generateAsync({ type: "arraybuffer" });
|
|
306
|
+
writeFileSync(this.outDir, Buffer.from(content));
|
|
307
|
+
}
|
|
308
|
+
getAllFiles(dirPath) {
|
|
309
|
+
const files = readdirSync(dirPath);
|
|
310
|
+
const result = [];
|
|
311
|
+
for (const file of files) {
|
|
312
|
+
const filePath = join(dirPath, file);
|
|
313
|
+
if (statSync(filePath).isDirectory()) {
|
|
314
|
+
result.push(...this.getAllFiles(filePath));
|
|
315
|
+
} else {
|
|
316
|
+
result.push(filePath);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const ctx$1 = new Ctx$1();
|
|
323
|
+
function zipPack() {
|
|
324
|
+
return {
|
|
325
|
+
name: "vite-plugin-zip",
|
|
326
|
+
apply: "build",
|
|
327
|
+
enforce: "post",
|
|
328
|
+
configResolved(configuration) {
|
|
329
|
+
const outDirName = configuration.build.outDir;
|
|
330
|
+
const root = configuration.root;
|
|
331
|
+
ctx$1.setOptions({ root, outDirName });
|
|
332
|
+
},
|
|
333
|
+
buildEnd() {
|
|
334
|
+
let isCompress = false;
|
|
335
|
+
process.on("beforeExit", async () => {
|
|
336
|
+
if (isCompress) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
consola.start("\u5C06\u6587\u4EF6\u5305\u538B\u7F29\u6210zip...");
|
|
340
|
+
isCompress = true;
|
|
341
|
+
await ctx$1.clean();
|
|
342
|
+
await ctx$1.compress();
|
|
343
|
+
consola.success("\u6587\u4EF6\u538B\u7F29\u5B8C\u6210");
|
|
344
|
+
consola.success("\u6253\u5305\u6D41\u7A0B\u7ED3\u675F!");
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function createZip() {
|
|
350
|
+
return zipPack();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function createIcons() {
|
|
354
|
+
return Icons({
|
|
355
|
+
autoInstall: false
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function createConsole() {
|
|
360
|
+
return TurboConsole({
|
|
361
|
+
disableLaunchEditor: true
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function createInspector(env) {
|
|
366
|
+
const { VITE_APP_INSPECTOR } = env;
|
|
367
|
+
if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") {
|
|
368
|
+
return VueDevTools();
|
|
369
|
+
} else {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function createOpenAPI() {
|
|
375
|
+
return OpenAPI();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function createConfig() {
|
|
379
|
+
return EnvRuntime({
|
|
380
|
+
name: "__PRODUCTION__PUBINFO__CONFIG__",
|
|
381
|
+
filename: "config.js",
|
|
382
|
+
include: [
|
|
383
|
+
"VITE_APP_TITLE",
|
|
384
|
+
"VITE_APP_API_BASEURL"
|
|
385
|
+
]
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
var __defProp = Object.defineProperty;
|
|
390
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
391
|
+
var __publicField = (obj, key, value) => {
|
|
392
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
393
|
+
return value;
|
|
394
|
+
};
|
|
395
|
+
class Ctx {
|
|
396
|
+
constructor() {
|
|
397
|
+
__publicField(this, "options");
|
|
398
|
+
}
|
|
399
|
+
setOptions(options) {
|
|
400
|
+
this.options = options;
|
|
401
|
+
}
|
|
402
|
+
async createInfo() {
|
|
403
|
+
console.log(
|
|
404
|
+
boxen(
|
|
405
|
+
`\u6B22\u8FCE\u4F7F\u7528${chalk.bold.greenBright(" \u6280\u672F\u5E95\u5EA7\u7BA1\u7406\u7CFB\u7EDF ")}
|
|
406
|
+
|
|
407
|
+
\u5982\u679C\u8981\u4FEE\u6539${chalk.yellow("config/*")} \u6216\u8005 ${chalk.yellow("scripts/*")}\u4E0B\u7684\u914D\u7F6E\u6587\u4EF6
|
|
408
|
+
\u8BF7\u5148\u6267\u884C${chalk.yellow(" pnpm run stub ")}\u542F\u52A8\u6587\u4EF6\u76D1\u542C\u7F16\u8BD1
|
|
409
|
+
|
|
410
|
+
${chalk.green("\u4F7F\u7528\u6587\u6863\u5730\u5740")} ${chalk.green("\u279C")} http://124.223.184.245:10000/docs
|
|
411
|
+
`,
|
|
412
|
+
{
|
|
413
|
+
padding: 1,
|
|
414
|
+
margin: 1,
|
|
415
|
+
align: "center",
|
|
416
|
+
borderColor: "yellowBright",
|
|
417
|
+
borderStyle: "round"
|
|
418
|
+
}
|
|
419
|
+
)
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const ctx = new Ctx();
|
|
424
|
+
function appInfo() {
|
|
425
|
+
return {
|
|
426
|
+
name: "appInfo",
|
|
427
|
+
apply: "serve",
|
|
428
|
+
enforce: "pre",
|
|
429
|
+
configResolved(configuration) {
|
|
430
|
+
const root = configuration.root;
|
|
431
|
+
ctx.setOptions({
|
|
432
|
+
root
|
|
433
|
+
});
|
|
434
|
+
},
|
|
435
|
+
async buildStart() {
|
|
436
|
+
ctx.createInfo();
|
|
437
|
+
},
|
|
438
|
+
configureServer(server) {
|
|
439
|
+
const _printUrls = server.printUrls;
|
|
440
|
+
server.printUrls = () => {
|
|
441
|
+
console.log(` ${chalk.green("\u279C")} ${chalk.bold.bgBlueBright(` PUBINFO `)}${chalk.bold.bgYellowBright(` \u524D\u7AEF\u57FA\u7840\u6846\u67B6 `)}`);
|
|
442
|
+
_printUrls();
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function createVitePlugins(viteEnv, isBuild = false) {
|
|
449
|
+
const vitePlugins = [
|
|
450
|
+
vue(),
|
|
451
|
+
vueJsx(),
|
|
452
|
+
vueLegacy(),
|
|
453
|
+
createAutoImport(),
|
|
454
|
+
createComponents(),
|
|
455
|
+
createUnocss(),
|
|
456
|
+
createSvgIcon(isBuild),
|
|
457
|
+
createIcons(),
|
|
458
|
+
createI18n(),
|
|
459
|
+
createMock(viteEnv, isBuild),
|
|
460
|
+
createLayouts(),
|
|
461
|
+
createBanner(),
|
|
462
|
+
createPreprocessor(),
|
|
463
|
+
createZip(),
|
|
464
|
+
createConsole(),
|
|
465
|
+
createInspector(viteEnv),
|
|
466
|
+
createOpenAPI(),
|
|
467
|
+
createConfig(),
|
|
468
|
+
appInfo()
|
|
469
|
+
];
|
|
470
|
+
const buildPlugins = () => [
|
|
471
|
+
...createCompression(viteEnv)
|
|
472
|
+
];
|
|
473
|
+
if (isBuild) {
|
|
474
|
+
vitePlugins.push(...buildPlugins());
|
|
475
|
+
}
|
|
476
|
+
return vitePlugins.filter(Boolean);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
async function createDefineSystemInfo(root) {
|
|
480
|
+
try {
|
|
481
|
+
const pkgJson = await readPackageJSON(root);
|
|
482
|
+
const { dependencies, devDependencies, version } = pkgJson;
|
|
483
|
+
const lastBuildTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
484
|
+
const SYSTEM_INFO = {
|
|
485
|
+
pkg: {
|
|
486
|
+
dependencies,
|
|
487
|
+
devDependencies,
|
|
488
|
+
version
|
|
489
|
+
},
|
|
490
|
+
lastBuildTime
|
|
491
|
+
};
|
|
492
|
+
return JSON.stringify(SYSTEM_INFO);
|
|
493
|
+
} catch (error) {
|
|
494
|
+
return "";
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function getServerProxy(env, isProxy, rewrite = true) {
|
|
498
|
+
if (!isProxy) {
|
|
499
|
+
return {};
|
|
500
|
+
}
|
|
501
|
+
const targetPrefix = "VITE_APP_API_";
|
|
502
|
+
const proxyKey = Object.keys(env).filter((key) => key.startsWith(targetPrefix));
|
|
503
|
+
const serverProxy = {};
|
|
504
|
+
for (const envKey of proxyKey) {
|
|
505
|
+
const url = env[envKey];
|
|
506
|
+
const { pathname } = new URL(url);
|
|
507
|
+
const pk = `${pathname}/proxy`;
|
|
508
|
+
if (pk in serverProxy) {
|
|
509
|
+
consola$1.error(`The proxy key ${chalk.bold.redBright(envKey)} \u279C ${chalk.bold.yellowBright(url)} already exists`);
|
|
510
|
+
} else {
|
|
511
|
+
serverProxy[pk] = {
|
|
512
|
+
target: url,
|
|
513
|
+
changeOrigin: rewrite,
|
|
514
|
+
rewrite: (path) => {
|
|
515
|
+
return path.replace(pk, "");
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return serverProxy;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function cleanse() {
|
|
524
|
+
return {
|
|
525
|
+
name: "esbuild-plugin-cleanse",
|
|
526
|
+
setup(build) {
|
|
527
|
+
build.onLoad({ filter: /\/dist\/alova\.esm\.js$/ }, async (args) => {
|
|
528
|
+
let alovaContnet = await fs.readFile(args.path, "utf-8");
|
|
529
|
+
alovaContnet = alovaContnet.replace(/\/\* c8 ignore start \*\/[\s\S]*?\/\* c8 ignore stop \*\//g, "");
|
|
530
|
+
return {
|
|
531
|
+
contents: `${alovaContnet}`
|
|
532
|
+
};
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function defineConfig(defineOptions = {}) {
|
|
539
|
+
return defineConfig$1(async ({ mode, command }) => {
|
|
540
|
+
const root = process.cwd();
|
|
541
|
+
const pathResolve = (pathname) => resolve$1(root, ".", pathname);
|
|
542
|
+
const env = loadEnv(mode, root);
|
|
543
|
+
const timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
544
|
+
const isBuild = command === "build";
|
|
545
|
+
const { VITE_OPEN_PROXY, VITE_BUILD_SOURCEMAP } = env;
|
|
546
|
+
const serverProxy = getServerProxy(env, !isBuild && VITE_OPEN_PROXY === "true");
|
|
547
|
+
const __SYSTEM_INFO__ = await createDefineSystemInfo(root);
|
|
548
|
+
const applicationConfig = {
|
|
549
|
+
base: "./",
|
|
550
|
+
server: {
|
|
551
|
+
open: true,
|
|
552
|
+
host: true,
|
|
553
|
+
proxy: serverProxy,
|
|
554
|
+
watch: {
|
|
555
|
+
ignored: ["!**/node_modules/@pubinfo/themes/src/system/**/*"]
|
|
556
|
+
},
|
|
557
|
+
warmup: {
|
|
558
|
+
clientFiles: [
|
|
559
|
+
"./index.html",
|
|
560
|
+
"./src/{layouts,components}/*",
|
|
561
|
+
"./src/locales/**/*"
|
|
562
|
+
]
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
resolve: {
|
|
566
|
+
alias: [
|
|
567
|
+
{
|
|
568
|
+
find: /@\//,
|
|
569
|
+
replacement: `${pathResolve("src")}/`
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
find: /#\//,
|
|
573
|
+
replacement: `${pathResolve("types")}/`
|
|
574
|
+
}
|
|
575
|
+
]
|
|
576
|
+
},
|
|
577
|
+
optimizeDeps: {
|
|
578
|
+
include: [
|
|
579
|
+
"ant-design-vue/es/locale/zh_CN",
|
|
580
|
+
"ant-design-vue/es/locale/en_US",
|
|
581
|
+
"@ant-design/icons-vue",
|
|
582
|
+
"dayjs",
|
|
583
|
+
"dayjs/locale/eu",
|
|
584
|
+
"dayjs/locale/zh-cn",
|
|
585
|
+
"@pubinfo/pro-components",
|
|
586
|
+
"qrcode",
|
|
587
|
+
"@pubinfo/headlessui"
|
|
588
|
+
],
|
|
589
|
+
esbuildOptions: {
|
|
590
|
+
plugins: [
|
|
591
|
+
cleanse()
|
|
592
|
+
]
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
build: {
|
|
596
|
+
outDir: mode === "production" ? "dist" : `dist-${mode}`,
|
|
597
|
+
sourcemap: VITE_BUILD_SOURCEMAP === "true",
|
|
598
|
+
reportCompressedSize: false,
|
|
599
|
+
chunkSizeWarningLimit: 2e3,
|
|
600
|
+
rollupOptions: {
|
|
601
|
+
output: {
|
|
602
|
+
entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`,
|
|
603
|
+
manualChunks: {
|
|
604
|
+
vue: ["vue", "pinia", "vue-router"],
|
|
605
|
+
lodash: ["lodash-es"],
|
|
606
|
+
antd: ["ant-design-vue", "@ant-design/icons-vue"],
|
|
607
|
+
lottie: ["lottie-web"]
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
define: {
|
|
613
|
+
__SYSTEM_INFO__,
|
|
614
|
+
_DEV_: mode === "development",
|
|
615
|
+
_PROD_: mode === "production"
|
|
616
|
+
},
|
|
617
|
+
plugins: createVitePlugins(env, isBuild)
|
|
618
|
+
};
|
|
619
|
+
return mergeConfig(applicationConfig, defineOptions);
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export { defineConfig };
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pubinfo/vite",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.6.3",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.mjs"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"vite": "^5.3.2",
|
|
18
|
+
"vue": "^3.4.31",
|
|
19
|
+
"vue-i18n": "^9.13.1"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@intlify/unplugin-vue-i18n": "^4.0.0",
|
|
23
|
+
"@pubinfo/unplugin-openapi": "^0.6.3",
|
|
24
|
+
"@vitejs/plugin-legacy": "^5.4.1",
|
|
25
|
+
"@vitejs/plugin-vue": "^5.0.5",
|
|
26
|
+
"@vitejs/plugin-vue-jsx": "^4.0.0",
|
|
27
|
+
"boxen": "^7.1.1",
|
|
28
|
+
"chalk": "^5.3.0",
|
|
29
|
+
"consola": "^3.2.3",
|
|
30
|
+
"dayjs": "^1.11.11",
|
|
31
|
+
"fast-glob": "^3.3.2",
|
|
32
|
+
"fs-extra": "^11.2.0",
|
|
33
|
+
"jszip": "^3.10.1",
|
|
34
|
+
"pkg-types": "^1.1.1",
|
|
35
|
+
"terser": "^5.31.1",
|
|
36
|
+
"unocss": "^0.61.0",
|
|
37
|
+
"unplugin-auto-import": "^0.17.6",
|
|
38
|
+
"unplugin-icons": "^0.19.0",
|
|
39
|
+
"unplugin-turbo-console": "^1.8.9",
|
|
40
|
+
"unplugin-vue-components": "^0.27.2",
|
|
41
|
+
"vite-plugin-banner": "^0.7.1",
|
|
42
|
+
"vite-plugin-compression": "^0.5.1",
|
|
43
|
+
"vite-plugin-env-runtime": "^0.3.5",
|
|
44
|
+
"vite-plugin-fake-server": "^2.1.1",
|
|
45
|
+
"vite-plugin-pages": "^0.32.3",
|
|
46
|
+
"vite-plugin-svg-icons": "^2.0.1",
|
|
47
|
+
"vite-plugin-vue-devtools": "^7.3.5",
|
|
48
|
+
"vite-plugin-vue-meta-layouts": "^0.4.3"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/fs-extra": "^11.0.4",
|
|
52
|
+
"esbuild": "^0.21.5",
|
|
53
|
+
"vite": "^5.3.2",
|
|
54
|
+
"vue": "^3.4.31",
|
|
55
|
+
"vue-i18n": "^9.13.1"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"clean": "pnpm rimraf node_modules dist .turbo",
|
|
59
|
+
"build": "unbuild",
|
|
60
|
+
"stub": "unbuild --stub",
|
|
61
|
+
"lint": "eslint . --cache --fix"
|
|
62
|
+
}
|
|
63
|
+
}
|