@pubinfo/vite 0.6.8 → 2.0.0-beta.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.cjs +413 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.mts +26 -4
- package/dist/index.d.ts +25 -7
- package/dist/index.mjs +200 -432
- package/package.json +30 -37
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vite = require('vite');
|
|
4
|
+
const node_process = require('node:process');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const consola = require('consola');
|
|
7
|
+
const node_module = require('node:module');
|
|
8
|
+
const node_path = require('node:path');
|
|
9
|
+
const vue = require('@vitejs/plugin-vue');
|
|
10
|
+
const vueJsx = require('@vitejs/plugin-vue-jsx');
|
|
11
|
+
const autoImport = require('unplugin-auto-import/vite');
|
|
12
|
+
const IconsResolver = require('unplugin-icons/resolver');
|
|
13
|
+
const resolvers = require('unplugin-vue-components/resolvers');
|
|
14
|
+
const components = require('unplugin-vue-components/vite');
|
|
15
|
+
const compression = require('vite-plugin-compression');
|
|
16
|
+
const Icons = require('unplugin-icons/vite');
|
|
17
|
+
const boxen = require('boxen');
|
|
18
|
+
const VueDevTools = require('vite-plugin-vue-devtools');
|
|
19
|
+
const vueLegacy = require('@vitejs/plugin-legacy');
|
|
20
|
+
const node_fs = require('node:fs');
|
|
21
|
+
const vitePluginFakeServer = require('vite-plugin-fake-server');
|
|
22
|
+
const OpenAPI = require('@pubinfo/unplugin-openapi/vite');
|
|
23
|
+
const Unocss = require('unocss/vite');
|
|
24
|
+
|
|
25
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
26
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
27
|
+
|
|
28
|
+
const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
29
|
+
const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
|
|
30
|
+
const vue__default = /*#__PURE__*/_interopDefaultCompat(vue);
|
|
31
|
+
const vueJsx__default = /*#__PURE__*/_interopDefaultCompat(vueJsx);
|
|
32
|
+
const autoImport__default = /*#__PURE__*/_interopDefaultCompat(autoImport);
|
|
33
|
+
const IconsResolver__default = /*#__PURE__*/_interopDefaultCompat(IconsResolver);
|
|
34
|
+
const components__default = /*#__PURE__*/_interopDefaultCompat(components);
|
|
35
|
+
const compression__default = /*#__PURE__*/_interopDefaultCompat(compression);
|
|
36
|
+
const Icons__default = /*#__PURE__*/_interopDefaultCompat(Icons);
|
|
37
|
+
const boxen__default = /*#__PURE__*/_interopDefaultCompat(boxen);
|
|
38
|
+
const VueDevTools__default = /*#__PURE__*/_interopDefaultCompat(VueDevTools);
|
|
39
|
+
const vueLegacy__default = /*#__PURE__*/_interopDefaultCompat(vueLegacy);
|
|
40
|
+
const OpenAPI__default = /*#__PURE__*/_interopDefaultCompat(OpenAPI);
|
|
41
|
+
const Unocss__default = /*#__PURE__*/_interopDefaultCompat(Unocss);
|
|
42
|
+
|
|
43
|
+
function alias(root) {
|
|
44
|
+
const resolvePath = (name) => node_path.join(root, name);
|
|
45
|
+
const resolveDeps = (name, path) => node_path.join(node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).resolve(name), path);
|
|
46
|
+
return {
|
|
47
|
+
"@": resolvePath("src"),
|
|
48
|
+
"#": resolvePath("types"),
|
|
49
|
+
// 提供路径别名给 @pubinfo/core 直接调用项目中的文件
|
|
50
|
+
"pubinfo:project": resolvePath("src"),
|
|
51
|
+
// 显示的列出导出的目录
|
|
52
|
+
// '.pubinfo': resolvePath('.pubinfo/'),
|
|
53
|
+
// '.pubinfo/api': resolvePath('.pubinfo/api/'),
|
|
54
|
+
// '.pubinfo/assets': resolvePath('.pubinfo/assets/'),
|
|
55
|
+
// '.pubinfo/config': resolvePath('.pubinfo/config/'),
|
|
56
|
+
// '.pubinfo/directives': resolvePath('.pubinfo/directives/'),
|
|
57
|
+
// '.pubinfo/layout': resolvePath('.pubinfo/layout/'),
|
|
58
|
+
// '.pubinfo/locales': resolvePath('.pubinfo/locales/'),
|
|
59
|
+
// '.pubinfo/router': resolvePath('.pubinfo/router/'),
|
|
60
|
+
// '.pubinfo/store': resolvePath('.pubinfo/store/'),
|
|
61
|
+
// '.pubinfo/styles': resolvePath('.pubinfo/styles/'),
|
|
62
|
+
// '.pubinfo/themes': resolvePath('.pubinfo/themes/'),
|
|
63
|
+
// '.pubinfo/types': resolvePath('.pubinfo/types/'),
|
|
64
|
+
// '.pubinfo/utils': resolvePath('.pubinfo/utils/'),
|
|
65
|
+
// '.pubinfo/vue': resolvePath('.pubinfo/vue/'),
|
|
66
|
+
// deps
|
|
67
|
+
"vue": resolveDeps("vue", "../"),
|
|
68
|
+
"vue-router": resolveDeps("vue-router", "../"),
|
|
69
|
+
"pinia": resolveDeps("pinia", "../"),
|
|
70
|
+
"unocss": resolveDeps("unocss", "../")
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getServerProxy(env, isProxy) {
|
|
75
|
+
if (!isProxy) {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
const targetPrefix = "VITE_APP_API_";
|
|
79
|
+
const proxyKey = Object.keys(env).filter((key) => key.startsWith(targetPrefix));
|
|
80
|
+
const serverProxy = {};
|
|
81
|
+
for (const envKey of proxyKey) {
|
|
82
|
+
const url = env[envKey];
|
|
83
|
+
const { pathname } = new URL(url);
|
|
84
|
+
const pk = `${pathname}/proxy`;
|
|
85
|
+
if (pk in serverProxy) {
|
|
86
|
+
consola__default.error(`The proxy key ${chalk__default.bold.redBright(envKey)} \u279C ${chalk__default.bold.yellowBright(url)} already exists`);
|
|
87
|
+
} else {
|
|
88
|
+
serverProxy[pk] = {
|
|
89
|
+
target: url,
|
|
90
|
+
changeOrigin: true,
|
|
91
|
+
rewrite: (path) => path.replace(pk, ""),
|
|
92
|
+
secure: false
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return serverProxy;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function createAutoImport() {
|
|
100
|
+
return autoImport__default({
|
|
101
|
+
imports: [
|
|
102
|
+
"vue",
|
|
103
|
+
"vue-router",
|
|
104
|
+
// 'vue-i18n',
|
|
105
|
+
"pinia",
|
|
106
|
+
{
|
|
107
|
+
pubinfo: [
|
|
108
|
+
"useAuth"
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
// 解决代码混淆后出现的h和vue导入的h变量命名重复的问题
|
|
113
|
+
ignore: ["h"],
|
|
114
|
+
dts: "./types/auto-imports.d.ts",
|
|
115
|
+
dirs: [
|
|
116
|
+
"./src/composables/**/*"
|
|
117
|
+
],
|
|
118
|
+
resolvers: [
|
|
119
|
+
resolvers.AntDesignVueResolver(),
|
|
120
|
+
IconsResolver__default({
|
|
121
|
+
prefix: "i"
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function createComponents() {
|
|
128
|
+
return components__default({
|
|
129
|
+
dirs: [
|
|
130
|
+
"src/components"
|
|
131
|
+
],
|
|
132
|
+
directives: true,
|
|
133
|
+
include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
|
|
134
|
+
resolvers: [
|
|
135
|
+
IconsResolver__default(),
|
|
136
|
+
resolvers.AntDesignVueResolver({
|
|
137
|
+
resolveIcons: true,
|
|
138
|
+
importStyle: false
|
|
139
|
+
}),
|
|
140
|
+
{
|
|
141
|
+
type: "component",
|
|
142
|
+
resolve(name) {
|
|
143
|
+
const components2 = [
|
|
144
|
+
"PubinfoApp",
|
|
145
|
+
"PubinfoProvider",
|
|
146
|
+
"PubinfoIcon"
|
|
147
|
+
];
|
|
148
|
+
if (components2.includes(name)) {
|
|
149
|
+
return { name, from: "pubinfo" };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
dts: "./types/components.d.ts"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function createCompression(env) {
|
|
159
|
+
const { VITE_BUILD_COMPRESS } = env;
|
|
160
|
+
const compressList = VITE_BUILD_COMPRESS?.split(",") ?? [];
|
|
161
|
+
const plugin = [];
|
|
162
|
+
if (compressList.includes("gzip")) {
|
|
163
|
+
plugin.push(
|
|
164
|
+
compression__default({
|
|
165
|
+
ext: ".gz",
|
|
166
|
+
deleteOriginFile: false
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (compressList.includes("brotli")) {
|
|
171
|
+
plugin.push(
|
|
172
|
+
compression__default({
|
|
173
|
+
ext: ".br",
|
|
174
|
+
algorithm: "brotliCompress",
|
|
175
|
+
deleteOriginFile: false
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return plugin;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function createIcons() {
|
|
183
|
+
return Icons__default({
|
|
184
|
+
autoInstall: false
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
class Ctx {
|
|
189
|
+
options;
|
|
190
|
+
setOptions(options) {
|
|
191
|
+
this.options = options;
|
|
192
|
+
}
|
|
193
|
+
async createInfo() {
|
|
194
|
+
console.log(
|
|
195
|
+
boxen__default(
|
|
196
|
+
`\u6B22\u8FCE\u4F7F\u7528${chalk__default.bold.greenBright(" \u6280\u672F\u5E95\u5EA7\u7BA1\u7406\u7CFB\u7EDF ")}
|
|
197
|
+
|
|
198
|
+
${chalk__default.green("\u4F7F\u7528\u6587\u6863\u5730\u5740")} ${chalk__default.green("\u279C")} https://134.108.39.195:9090/docs`,
|
|
199
|
+
{
|
|
200
|
+
padding: 1,
|
|
201
|
+
margin: 1,
|
|
202
|
+
align: "center",
|
|
203
|
+
borderColor: "yellowBright",
|
|
204
|
+
borderStyle: "round"
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const ctx = new Ctx();
|
|
211
|
+
function appInfo() {
|
|
212
|
+
return {
|
|
213
|
+
name: "appInfo",
|
|
214
|
+
apply: "serve",
|
|
215
|
+
enforce: "pre",
|
|
216
|
+
configResolved(configuration) {
|
|
217
|
+
const root = configuration.root;
|
|
218
|
+
ctx.setOptions({
|
|
219
|
+
root
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
async buildStart() {
|
|
223
|
+
ctx.createInfo();
|
|
224
|
+
},
|
|
225
|
+
configureServer(server) {
|
|
226
|
+
const _printUrls = server.printUrls;
|
|
227
|
+
server.printUrls = () => {
|
|
228
|
+
console.log(` ${chalk__default.green("\u279C")} ${chalk__default.bold.bgBlueBright(` PUBINFO `)}${chalk__default.bold.bgYellowBright(` \u524D\u7AEF\u57FA\u7840\u6846\u67B6 `)}`);
|
|
229
|
+
_printUrls();
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function createInspector(env) {
|
|
236
|
+
const { VITE_APP_INSPECTOR } = env;
|
|
237
|
+
if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") {
|
|
238
|
+
return VueDevTools__default();
|
|
239
|
+
} else {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function createLegacy(env) {
|
|
245
|
+
if (env.VITE_BUILD_LEGACY !== "true") {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
return vueLegacy__default({
|
|
249
|
+
modernPolyfills: [
|
|
250
|
+
"es.array.at",
|
|
251
|
+
"es.array.find-last"
|
|
252
|
+
],
|
|
253
|
+
additionalLegacyPolyfills: ["abort-controller/polyfill"]
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function createMock(env, isBuild) {
|
|
258
|
+
const { VITE_BUILD_MOCK } = env;
|
|
259
|
+
if (!node_fs.existsSync(node_path.resolve(node_process.cwd(), "src/mock"))) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
return vitePluginFakeServer.vitePluginFakeServer({
|
|
263
|
+
logger: !isBuild,
|
|
264
|
+
include: "src/mock",
|
|
265
|
+
infixName: false,
|
|
266
|
+
enableProd: isBuild && VITE_BUILD_MOCK === "true"
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function createOpenAPI(options) {
|
|
271
|
+
return OpenAPI__default(options || { enabled: false });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function createUnocss() {
|
|
275
|
+
return Unocss__default();
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function createVitePlugins(viteEnv, isBuild = false, config) {
|
|
279
|
+
const vitePlugins = [
|
|
280
|
+
vue__default(),
|
|
281
|
+
vueJsx__default(),
|
|
282
|
+
createLegacy(viteEnv),
|
|
283
|
+
createAutoImport(),
|
|
284
|
+
createComponents(),
|
|
285
|
+
createUnocss(),
|
|
286
|
+
createIcons(),
|
|
287
|
+
createMock(viteEnv, isBuild),
|
|
288
|
+
createInspector(viteEnv),
|
|
289
|
+
createOpenAPI(config.openapi),
|
|
290
|
+
appInfo()
|
|
291
|
+
];
|
|
292
|
+
const buildPlugins = () => [
|
|
293
|
+
...createCompression(viteEnv)
|
|
294
|
+
];
|
|
295
|
+
if (isBuild) {
|
|
296
|
+
vitePlugins.push(...buildPlugins());
|
|
297
|
+
}
|
|
298
|
+
return vitePlugins.filter(Boolean);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function createDefaultAppConfig(config) {
|
|
302
|
+
return ({ mode, command }) => {
|
|
303
|
+
const root = node_process.cwd();
|
|
304
|
+
const isBuild = command === "build";
|
|
305
|
+
const timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
306
|
+
const env = vite.loadEnv(mode, root);
|
|
307
|
+
const { VITE_OPEN_PROXY, VITE_BUILD_SOURCEMAP } = env;
|
|
308
|
+
const serverProxy = getServerProxy(env, !isBuild && VITE_OPEN_PROXY === "true");
|
|
309
|
+
const applicationConfig = {
|
|
310
|
+
base: "./",
|
|
311
|
+
server: {
|
|
312
|
+
open: true,
|
|
313
|
+
host: true,
|
|
314
|
+
proxy: serverProxy,
|
|
315
|
+
warmup: {
|
|
316
|
+
clientFiles: [
|
|
317
|
+
"./index.html"
|
|
318
|
+
]
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
// To fix some dev problems
|
|
322
|
+
optimizeDeps: {
|
|
323
|
+
exclude: [
|
|
324
|
+
"pubinfo",
|
|
325
|
+
"@pubinfo/core"
|
|
326
|
+
]
|
|
327
|
+
},
|
|
328
|
+
resolve: {
|
|
329
|
+
alias: alias(root)
|
|
330
|
+
},
|
|
331
|
+
build: {
|
|
332
|
+
outDir: mode === "production" ? "dist" : `dist-${mode}`,
|
|
333
|
+
sourcemap: VITE_BUILD_SOURCEMAP === "true",
|
|
334
|
+
reportCompressedSize: false,
|
|
335
|
+
chunkSizeWarningLimit: 2e3,
|
|
336
|
+
rollupOptions: {
|
|
337
|
+
output: {
|
|
338
|
+
entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
plugins: createVitePlugins(env, isBuild, config)
|
|
343
|
+
};
|
|
344
|
+
return applicationConfig;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function createDefaultModuleConfig(config) {
|
|
349
|
+
return ({ mode, command }) => {
|
|
350
|
+
const root = node_process.cwd();
|
|
351
|
+
const isBuild = command === "build";
|
|
352
|
+
const env = vite.loadEnv(mode, root);
|
|
353
|
+
const applicationConfig = {
|
|
354
|
+
// To fix some dev problems
|
|
355
|
+
optimizeDeps: {
|
|
356
|
+
exclude: [
|
|
357
|
+
"pubinfo",
|
|
358
|
+
"@pubinfo/core"
|
|
359
|
+
]
|
|
360
|
+
},
|
|
361
|
+
resolve: {
|
|
362
|
+
alias: alias(root)
|
|
363
|
+
},
|
|
364
|
+
build: {
|
|
365
|
+
rollupOptions: {
|
|
366
|
+
external: [
|
|
367
|
+
"vue",
|
|
368
|
+
"vue-router",
|
|
369
|
+
"pinia",
|
|
370
|
+
"unocss"
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
plugins: createVitePlugins(env, isBuild, config)
|
|
375
|
+
};
|
|
376
|
+
return applicationConfig;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function definePubinfoConfig(config) {
|
|
381
|
+
return {
|
|
382
|
+
...config,
|
|
383
|
+
vite: mergeViteConfig(createDefaultAppConfig(config), config)
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function defineModuleConfig(config) {
|
|
387
|
+
return {
|
|
388
|
+
...config,
|
|
389
|
+
vite: mergeViteConfig(createDefaultModuleConfig(config), config)
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function mergeViteConfig(defaultOptions, config = {}) {
|
|
393
|
+
const { vite: viteOptions = {} } = config;
|
|
394
|
+
return vite.defineConfig(({ mode, command }) => {
|
|
395
|
+
return vite.mergeConfig(
|
|
396
|
+
defaultOptions({ mode, command }),
|
|
397
|
+
typeof viteOptions === "function" ? viteOptions({ mode, command }) : viteOptions
|
|
398
|
+
);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
exports.defineModuleConfig = defineModuleConfig;
|
|
403
|
+
exports.definePubinfoConfig = definePubinfoConfig;
|
|
404
|
+
Object.prototype.hasOwnProperty.call(vite, '__proto__') &&
|
|
405
|
+
!Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
|
|
406
|
+
Object.defineProperty(exports, '__proto__', {
|
|
407
|
+
enumerable: true,
|
|
408
|
+
value: vite['__proto__']
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
Object.keys(vite).forEach(function (k) {
|
|
412
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = vite[k];
|
|
413
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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 { defineModuleConfig, definePubinfoConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
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';
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
interface PubinfoConfig {
|
|
7
|
+
/** `vite` */
|
|
8
|
+
vite?: UserConfig | UserConfigFnObject;
|
|
9
|
+
/** `@pubinfo/unplugin-openapi` */
|
|
10
|
+
openapi?: Options;
|
|
11
|
+
}
|
|
5
12
|
|
|
6
|
-
|
|
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 { defineModuleConfig, definePubinfoConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
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
5
|
|
|
2
|
-
|
|
3
|
-
|
|
6
|
+
interface PubinfoConfig {
|
|
7
|
+
/** `vite` */
|
|
8
|
+
vite?: UserConfig | UserConfigFnObject;
|
|
9
|
+
/** `@pubinfo/unplugin-openapi` */
|
|
10
|
+
openapi?: Options;
|
|
11
|
+
}
|
|
4
12
|
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
};
|
|
7
27
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export { defineConfig };
|
|
28
|
+
export { defineModuleConfig, definePubinfoConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,49 +1,80 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
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';
|
|
4
8
|
import vue from '@vitejs/plugin-vue';
|
|
5
9
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
6
|
-
import vueLegacy from '@vitejs/plugin-legacy';
|
|
7
10
|
import autoImport from 'unplugin-auto-import/vite';
|
|
8
|
-
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
|
|
9
11
|
import IconsResolver from 'unplugin-icons/resolver';
|
|
12
|
+
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
|
|
10
13
|
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 { existsSync, readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs';
|
|
15
|
-
import { vitePluginFakeServer } from 'vite-plugin-fake-server';
|
|
16
14
|
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 JSZip from 'jszip';
|
|
22
|
-
import fse from 'fs-extra/esm';
|
|
23
|
-
import consola$1, { consola } from 'consola';
|
|
24
15
|
import Icons from 'unplugin-icons/vite';
|
|
25
|
-
import
|
|
16
|
+
import boxen from 'boxen';
|
|
26
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';
|
|
27
21
|
import OpenAPI from '@pubinfo/unplugin-openapi/vite';
|
|
28
|
-
import
|
|
29
|
-
import boxen from 'boxen';
|
|
30
|
-
import chalk from 'chalk';
|
|
31
|
-
import { readPackageJSON } from 'pkg-types';
|
|
32
|
-
import fs from 'node:fs/promises';
|
|
22
|
+
import Unocss from 'unocss/vite';
|
|
33
23
|
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
24
|
+
function alias(root) {
|
|
25
|
+
const resolvePath = (name) => join(root, name);
|
|
26
|
+
const resolveDeps = (name, path) => join(createRequire(import.meta.url).resolve(name), path);
|
|
38
27
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
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", "../")
|
|
41
52
|
};
|
|
42
53
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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;
|
|
47
78
|
}
|
|
48
79
|
|
|
49
80
|
function createAutoImport() {
|
|
@@ -51,72 +82,33 @@ function createAutoImport() {
|
|
|
51
82
|
imports: [
|
|
52
83
|
"vue",
|
|
53
84
|
"vue-router",
|
|
54
|
-
|
|
55
|
-
"
|
|
85
|
+
// 'vue-i18n',
|
|
86
|
+
"pinia",
|
|
56
87
|
{
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
"invalidateCache"
|
|
88
|
+
pubinfo: [
|
|
89
|
+
"useAuth"
|
|
60
90
|
]
|
|
61
91
|
}
|
|
62
92
|
],
|
|
93
|
+
// 解决代码混淆后出现的h和vue导入的h变量命名重复的问题
|
|
94
|
+
ignore: ["h"],
|
|
63
95
|
dts: "./types/auto-imports.d.ts",
|
|
64
96
|
dirs: [
|
|
65
|
-
"./src/
|
|
66
|
-
"./src/composables/**/*",
|
|
67
|
-
"./src/api/modules/**/*.ts"
|
|
97
|
+
"./src/composables/**/*"
|
|
68
98
|
],
|
|
69
99
|
resolvers: [
|
|
70
100
|
AntDesignVueResolver(),
|
|
71
101
|
IconsResolver({
|
|
72
102
|
prefix: "i"
|
|
73
|
-
})
|
|
74
|
-
PubInfoResolver$1()
|
|
103
|
+
})
|
|
75
104
|
]
|
|
76
105
|
});
|
|
77
106
|
}
|
|
78
107
|
|
|
79
|
-
function resolveComponent(componentName) {
|
|
80
|
-
if (!componentName.match(/^Pub[A-Z]/)) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
name: componentName,
|
|
85
|
-
as: componentName,
|
|
86
|
-
from: "@pubinfo/components"
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function resolveDirective(directiveName) {
|
|
90
|
-
if (!directiveName.match(/^Pub[A-Z]/)) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
name: directiveName,
|
|
95
|
-
from: "@pubinfo/directives"
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function PubInfoResolver() {
|
|
99
|
-
return [
|
|
100
|
-
{
|
|
101
|
-
type: "component",
|
|
102
|
-
resolve: async (name) => {
|
|
103
|
-
return resolveComponent(name);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
type: "directive",
|
|
108
|
-
resolve: async (name) => {
|
|
109
|
-
return resolveDirective(name);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
108
|
function createComponents() {
|
|
116
109
|
return components({
|
|
117
110
|
dirs: [
|
|
118
|
-
"src/components"
|
|
119
|
-
"src/layouts/ui-kit"
|
|
111
|
+
"src/components"
|
|
120
112
|
],
|
|
121
113
|
directives: true,
|
|
122
114
|
include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
|
|
@@ -126,46 +118,24 @@ function createComponents() {
|
|
|
126
118
|
resolveIcons: true,
|
|
127
119
|
importStyle: false
|
|
128
120
|
}),
|
|
129
|
-
|
|
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
|
+
}
|
|
130
134
|
],
|
|
131
135
|
dts: "./types/components.d.ts"
|
|
132
136
|
});
|
|
133
137
|
}
|
|
134
138
|
|
|
135
|
-
function createUnocss() {
|
|
136
|
-
return Unocss();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function createSvgIcon(isBuild) {
|
|
140
|
-
return createSvgIconsPlugin({
|
|
141
|
-
iconDirs: [path.resolve(process.cwd(), "src/assets/icons/")],
|
|
142
|
-
symbolId: "icon-[dir]-[name]",
|
|
143
|
-
svgoOptions: isBuild
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function createI18n() {
|
|
148
|
-
const root = process.cwd();
|
|
149
|
-
const pathResolve = (pathname) => resolve$1(root, ".", pathname);
|
|
150
|
-
return vueI18n({
|
|
151
|
-
include: `${pathResolve("src")}/locales/lang/**`
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function createMock(env, isBuild) {
|
|
156
|
-
const { VITE_BUILD_MOCK } = env;
|
|
157
|
-
const root = process.cwd();
|
|
158
|
-
if (!existsSync(resolve$1(root, "src/mock"))) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
return vitePluginFakeServer({
|
|
162
|
-
logger: !isBuild,
|
|
163
|
-
include: "src/mock",
|
|
164
|
-
infixName: false,
|
|
165
|
-
enableProd: isBuild && VITE_BUILD_MOCK === "true"
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
139
|
function createCompression(env) {
|
|
170
140
|
const { VITE_BUILD_COMPRESS } = env;
|
|
171
141
|
const compressList = VITE_BUILD_COMPRESS?.split(",") ?? [];
|
|
@@ -190,209 +160,14 @@ function createCompression(env) {
|
|
|
190
160
|
return plugin;
|
|
191
161
|
}
|
|
192
162
|
|
|
193
|
-
const deploymentTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
194
|
-
function createBanner() {
|
|
195
|
-
return banner(`
|
|
196
|
-
/**
|
|
197
|
-
* \u7531 \u793E\u4F1A\u6CBB\u7406\u4E8B\u4E1A\u90E8 \u63D0\u4F9B\u6280\u672F\u652F\u6301
|
|
198
|
-
* Powered by wsy-admin
|
|
199
|
-
* ${deploymentTime}
|
|
200
|
-
*/
|
|
201
|
-
`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
var __defProp$2 = Object.defineProperty;
|
|
205
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
206
|
-
var __publicField$2 = (obj, key, value) => {
|
|
207
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
208
|
-
return value;
|
|
209
|
-
};
|
|
210
|
-
let Ctx$2 = class Ctx {
|
|
211
|
-
constructor(options) {
|
|
212
|
-
__publicField$2(this, "root");
|
|
213
|
-
__publicField$2(this, "globs");
|
|
214
|
-
__publicField$2(this, "sourcePath");
|
|
215
|
-
__publicField$2(this, "path");
|
|
216
|
-
this.globs = options.globs;
|
|
217
|
-
}
|
|
218
|
-
setRoot(root) {
|
|
219
|
-
this.root = root;
|
|
220
|
-
}
|
|
221
|
-
searchGlob() {
|
|
222
|
-
const { root, globs } = this;
|
|
223
|
-
this.sourcePath = fg.sync(globs, {
|
|
224
|
-
cwd: root,
|
|
225
|
-
onlyFiles: true
|
|
226
|
-
});
|
|
227
|
-
this.normalizePath();
|
|
228
|
-
}
|
|
229
|
-
normalizePath() {
|
|
230
|
-
const path = [];
|
|
231
|
-
for (const f of this.sourcePath) {
|
|
232
|
-
path.push(`@use "${f}" as *;`);
|
|
233
|
-
}
|
|
234
|
-
this.path = path.join("");
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
function scssPreprocessor(options) {
|
|
238
|
-
const ctx = new Ctx$2(options);
|
|
239
|
-
return {
|
|
240
|
-
name: "vite-plugin-scssPreprocessor",
|
|
241
|
-
enforce: "pre",
|
|
242
|
-
config: (config) => {
|
|
243
|
-
ctx.setRoot(config.root);
|
|
244
|
-
ctx.searchGlob();
|
|
245
|
-
return {
|
|
246
|
-
css: {
|
|
247
|
-
preprocessorOptions: {
|
|
248
|
-
scss: {
|
|
249
|
-
additionalData: ctx.path
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
function createPreprocessor() {
|
|
258
|
-
return scssPreprocessor({
|
|
259
|
-
globs: ["src/assets/styles/resources/*.scss"]
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
var __defProp$1 = Object.defineProperty;
|
|
264
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
265
|
-
var __publicField$1 = (obj, key, value) => {
|
|
266
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
267
|
-
return value;
|
|
268
|
-
};
|
|
269
|
-
let Ctx$1 = class Ctx {
|
|
270
|
-
constructor() {
|
|
271
|
-
__publicField$1(this, "root");
|
|
272
|
-
__publicField$1(this, "outDirName");
|
|
273
|
-
__publicField$1(this, "dir");
|
|
274
|
-
__publicField$1(this, "outDir");
|
|
275
|
-
}
|
|
276
|
-
setOptions(options) {
|
|
277
|
-
this.root = options.root;
|
|
278
|
-
this.outDirName = options.outDirName;
|
|
279
|
-
this.getDirPath();
|
|
280
|
-
}
|
|
281
|
-
getDirPath() {
|
|
282
|
-
const dir = resolve$1(this.root, this.outDirName);
|
|
283
|
-
const outDir = `${dir}.zip`;
|
|
284
|
-
this.dir = dir;
|
|
285
|
-
this.outDir = outDir;
|
|
286
|
-
}
|
|
287
|
-
async clean() {
|
|
288
|
-
const pathExists = await fse.pathExists(this.outDir);
|
|
289
|
-
if (pathExists) {
|
|
290
|
-
fse.remove(this.outDir);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async compress() {
|
|
294
|
-
const zip = new JSZip();
|
|
295
|
-
const files = this.getAllFiles(this.dir);
|
|
296
|
-
if (files && Array.isArray(files) && files.length) {
|
|
297
|
-
files.forEach((file) => {
|
|
298
|
-
const fileData = readFileSync(file, { encoding: "binary" });
|
|
299
|
-
zip.file(relative(this.dir, file), fileData, { binary: true });
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
const content = await zip.generateAsync({ type: "arraybuffer" });
|
|
303
|
-
writeFileSync(this.outDir, Buffer.from(content));
|
|
304
|
-
}
|
|
305
|
-
getAllFiles(dirPath) {
|
|
306
|
-
const files = readdirSync(dirPath);
|
|
307
|
-
const result = [];
|
|
308
|
-
for (const file of files) {
|
|
309
|
-
const filePath = join(dirPath, file);
|
|
310
|
-
if (statSync(filePath).isDirectory()) {
|
|
311
|
-
result.push(...this.getAllFiles(filePath));
|
|
312
|
-
} else {
|
|
313
|
-
result.push(filePath);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return result;
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
const ctx$1 = new Ctx$1();
|
|
320
|
-
function zipPack() {
|
|
321
|
-
return {
|
|
322
|
-
name: "vite-plugin-zip",
|
|
323
|
-
apply: "build",
|
|
324
|
-
enforce: "post",
|
|
325
|
-
configResolved(configuration) {
|
|
326
|
-
const outDirName = configuration.build.outDir;
|
|
327
|
-
const root = configuration.root;
|
|
328
|
-
ctx$1.setOptions({ root, outDirName });
|
|
329
|
-
},
|
|
330
|
-
buildEnd() {
|
|
331
|
-
let isCompress = false;
|
|
332
|
-
process.on("beforeExit", async () => {
|
|
333
|
-
if (isCompress) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
consola.start("\u5C06\u6587\u4EF6\u5305\u538B\u7F29\u6210zip...");
|
|
337
|
-
isCompress = true;
|
|
338
|
-
await ctx$1.clean();
|
|
339
|
-
await ctx$1.compress();
|
|
340
|
-
consola.success("\u6587\u4EF6\u538B\u7F29\u5B8C\u6210");
|
|
341
|
-
consola.success("\u6253\u5305\u6D41\u7A0B\u7ED3\u675F!");
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
function createZip() {
|
|
347
|
-
return zipPack();
|
|
348
|
-
}
|
|
349
|
-
|
|
350
163
|
function createIcons() {
|
|
351
164
|
return Icons({
|
|
352
165
|
autoInstall: false
|
|
353
166
|
});
|
|
354
167
|
}
|
|
355
168
|
|
|
356
|
-
function createConsole() {
|
|
357
|
-
return TurboConsole({
|
|
358
|
-
disableLaunchEditor: true
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function createInspector(env) {
|
|
363
|
-
const { VITE_APP_INSPECTOR } = env;
|
|
364
|
-
if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") {
|
|
365
|
-
return VueDevTools();
|
|
366
|
-
} else {
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function createOpenAPI() {
|
|
372
|
-
return OpenAPI();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function createConfig() {
|
|
376
|
-
return EnvRuntime({
|
|
377
|
-
name: "__PRODUCTION__PUBINFO__CONFIG__",
|
|
378
|
-
filename: "config.js",
|
|
379
|
-
include: [
|
|
380
|
-
"VITE_APP_TITLE",
|
|
381
|
-
"VITE_APP_API_BASEURL"
|
|
382
|
-
]
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
var __defProp = Object.defineProperty;
|
|
387
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
388
|
-
var __publicField = (obj, key, value) => {
|
|
389
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
390
|
-
return value;
|
|
391
|
-
};
|
|
392
169
|
class Ctx {
|
|
393
|
-
|
|
394
|
-
__publicField(this, "options");
|
|
395
|
-
}
|
|
170
|
+
options;
|
|
396
171
|
setOptions(options) {
|
|
397
172
|
this.options = options;
|
|
398
173
|
}
|
|
@@ -438,25 +213,61 @@ function appInfo() {
|
|
|
438
213
|
};
|
|
439
214
|
}
|
|
440
215
|
|
|
441
|
-
function
|
|
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) {
|
|
442
260
|
const vitePlugins = [
|
|
443
261
|
vue(),
|
|
444
262
|
vueJsx(),
|
|
445
|
-
|
|
263
|
+
createLegacy(viteEnv),
|
|
446
264
|
createAutoImport(),
|
|
447
265
|
createComponents(),
|
|
448
266
|
createUnocss(),
|
|
449
|
-
createSvgIcon(isBuild),
|
|
450
267
|
createIcons(),
|
|
451
|
-
createI18n(),
|
|
452
268
|
createMock(viteEnv, isBuild),
|
|
453
|
-
createBanner(),
|
|
454
|
-
createPreprocessor(),
|
|
455
|
-
createZip(),
|
|
456
|
-
createConsole(),
|
|
457
269
|
createInspector(viteEnv),
|
|
458
|
-
createOpenAPI(),
|
|
459
|
-
createConfig(),
|
|
270
|
+
createOpenAPI(config.openapi),
|
|
460
271
|
appInfo()
|
|
461
272
|
];
|
|
462
273
|
const buildPlugins = () => [
|
|
@@ -468,70 +279,9 @@ function createVitePlugins(viteEnv, isBuild = false) {
|
|
|
468
279
|
return vitePlugins.filter(Boolean);
|
|
469
280
|
}
|
|
470
281
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const
|
|
474
|
-
const { dependencies, devDependencies, version } = pkgJson;
|
|
475
|
-
const lastBuildTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
476
|
-
const SYSTEM_INFO = {
|
|
477
|
-
pkg: {
|
|
478
|
-
dependencies,
|
|
479
|
-
devDependencies,
|
|
480
|
-
version
|
|
481
|
-
},
|
|
482
|
-
lastBuildTime
|
|
483
|
-
};
|
|
484
|
-
return JSON.stringify(SYSTEM_INFO);
|
|
485
|
-
} catch (error) {
|
|
486
|
-
return "";
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
function getServerProxy(env, isProxy, rewrite = true) {
|
|
490
|
-
if (!isProxy) {
|
|
491
|
-
return {};
|
|
492
|
-
}
|
|
493
|
-
const targetPrefix = "VITE_APP_API_";
|
|
494
|
-
const proxyKey = Object.keys(env).filter((key) => key.startsWith(targetPrefix));
|
|
495
|
-
const serverProxy = {};
|
|
496
|
-
for (const envKey of proxyKey) {
|
|
497
|
-
const url = env[envKey];
|
|
498
|
-
const { pathname } = new URL(url);
|
|
499
|
-
const pk = `${pathname}/proxy`;
|
|
500
|
-
if (pk in serverProxy) {
|
|
501
|
-
consola$1.error(`The proxy key ${chalk.bold.redBright(envKey)} \u279C ${chalk.bold.yellowBright(url)} already exists`);
|
|
502
|
-
} else {
|
|
503
|
-
serverProxy[pk] = {
|
|
504
|
-
target: url,
|
|
505
|
-
changeOrigin: rewrite,
|
|
506
|
-
rewrite: (path) => {
|
|
507
|
-
return path.replace(pk, "");
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
return serverProxy;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
function cleanse() {
|
|
516
|
-
return {
|
|
517
|
-
name: "esbuild-plugin-cleanse",
|
|
518
|
-
setup(build) {
|
|
519
|
-
build.onLoad({ filter: /\/dist\/alova\.esm\.js$/ }, async (args) => {
|
|
520
|
-
let alovaContnet = await fs.readFile(args.path, "utf-8");
|
|
521
|
-
alovaContnet = alovaContnet.replace(/\/\* c8 ignore start \*\/[\s\S]*?\/\* c8 ignore stop \*\//g, "");
|
|
522
|
-
return {
|
|
523
|
-
contents: `${alovaContnet}`
|
|
524
|
-
};
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
function defineConfig(defineOptions = {}) {
|
|
531
|
-
return defineConfig$1(async ({ mode, command }) => {
|
|
532
|
-
const root = process.cwd();
|
|
533
|
-
const pathResolve = (pathname) => resolve$1(root, ".", pathname);
|
|
534
|
-
const __SYSTEM_INFO__ = await createDefineSystemInfo(root);
|
|
282
|
+
function createDefaultAppConfig(config) {
|
|
283
|
+
return ({ mode, command }) => {
|
|
284
|
+
const root = cwd();
|
|
535
285
|
const isBuild = command === "build";
|
|
536
286
|
const timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
537
287
|
const env = loadEnv(mode, root);
|
|
@@ -543,46 +293,21 @@ function defineConfig(defineOptions = {}) {
|
|
|
543
293
|
open: true,
|
|
544
294
|
host: true,
|
|
545
295
|
proxy: serverProxy,
|
|
546
|
-
watch: {
|
|
547
|
-
ignored: ["!**/node_modules/@pubinfo/themes/src/system/**/*"]
|
|
548
|
-
},
|
|
549
296
|
warmup: {
|
|
550
297
|
clientFiles: [
|
|
551
|
-
"./index.html"
|
|
552
|
-
"./src/{layouts,components}/*",
|
|
553
|
-
"./src/locales/**/*"
|
|
298
|
+
"./index.html"
|
|
554
299
|
]
|
|
555
300
|
}
|
|
556
301
|
},
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
},
|
|
563
|
-
{
|
|
564
|
-
find: /#\//,
|
|
565
|
-
replacement: `${pathResolve("types")}/`
|
|
566
|
-
}
|
|
302
|
+
// To fix some dev problems
|
|
303
|
+
optimizeDeps: {
|
|
304
|
+
exclude: [
|
|
305
|
+
"pubinfo",
|
|
306
|
+
"@pubinfo/core"
|
|
567
307
|
]
|
|
568
308
|
},
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
// 'ant-design-vue/es/locale/zh_CN',
|
|
572
|
-
// 'ant-design-vue/es/locale/en_US',
|
|
573
|
-
// '@ant-design/icons-vue',
|
|
574
|
-
// 'dayjs',
|
|
575
|
-
// 'dayjs/locale/eu',
|
|
576
|
-
// 'dayjs/locale/zh-cn',
|
|
577
|
-
// '@pubinfo/pro-components',
|
|
578
|
-
// 'qrcode',
|
|
579
|
-
// '@pubinfo/headlessui',
|
|
580
|
-
// ],
|
|
581
|
-
esbuildOptions: {
|
|
582
|
-
plugins: [
|
|
583
|
-
cleanse()
|
|
584
|
-
]
|
|
585
|
-
}
|
|
309
|
+
resolve: {
|
|
310
|
+
alias: alias(root)
|
|
586
311
|
},
|
|
587
312
|
build: {
|
|
588
313
|
outDir: mode === "production" ? "dist" : `dist-${mode}`,
|
|
@@ -592,24 +317,67 @@ function defineConfig(defineOptions = {}) {
|
|
|
592
317
|
rollupOptions: {
|
|
593
318
|
output: {
|
|
594
319
|
entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`
|
|
595
|
-
// manualChunks: {
|
|
596
|
-
// vue: ['vue', 'pinia', 'vue-router'],
|
|
597
|
-
// lodash: ['lodash-es'],
|
|
598
|
-
// antd: ['ant-design-vue', '@ant-design/icons-vue'],
|
|
599
|
-
// lottie: ['lottie-web'],
|
|
600
|
-
// },
|
|
601
320
|
}
|
|
602
321
|
}
|
|
603
322
|
},
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
323
|
+
plugins: createVitePlugins(env, isBuild, config)
|
|
324
|
+
};
|
|
325
|
+
return applicationConfig;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function createDefaultModuleConfig(config) {
|
|
330
|
+
return ({ mode, command }) => {
|
|
331
|
+
const root = cwd();
|
|
332
|
+
const isBuild = command === "build";
|
|
333
|
+
const env = loadEnv(mode, root);
|
|
334
|
+
const applicationConfig = {
|
|
335
|
+
// To fix some dev problems
|
|
336
|
+
optimizeDeps: {
|
|
337
|
+
exclude: [
|
|
338
|
+
"pubinfo",
|
|
339
|
+
"@pubinfo/core"
|
|
340
|
+
]
|
|
608
341
|
},
|
|
609
|
-
|
|
342
|
+
resolve: {
|
|
343
|
+
alias: alias(root)
|
|
344
|
+
},
|
|
345
|
+
build: {
|
|
346
|
+
rollupOptions: {
|
|
347
|
+
external: [
|
|
348
|
+
"vue",
|
|
349
|
+
"vue-router",
|
|
350
|
+
"pinia",
|
|
351
|
+
"unocss"
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
plugins: createVitePlugins(env, isBuild, config)
|
|
610
356
|
};
|
|
611
|
-
return
|
|
357
|
+
return applicationConfig;
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function definePubinfoConfig(config) {
|
|
362
|
+
return {
|
|
363
|
+
...config,
|
|
364
|
+
vite: mergeViteConfig(createDefaultAppConfig(config), config)
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function defineModuleConfig(config) {
|
|
368
|
+
return {
|
|
369
|
+
...config,
|
|
370
|
+
vite: mergeViteConfig(createDefaultModuleConfig(config), config)
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function mergeViteConfig(defaultOptions, config = {}) {
|
|
374
|
+
const { vite: viteOptions = {} } = config;
|
|
375
|
+
return defineConfig(({ mode, command }) => {
|
|
376
|
+
return mergeConfig(
|
|
377
|
+
defaultOptions({ mode, command }),
|
|
378
|
+
typeof viteOptions === "function" ? viteOptions({ mode, command }) : viteOptions
|
|
379
|
+
);
|
|
612
380
|
});
|
|
613
381
|
}
|
|
614
382
|
|
|
615
|
-
export {
|
|
383
|
+
export { defineModuleConfig, definePubinfoConfig };
|
package/package.json
CHANGED
|
@@ -1,62 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubinfo/vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "2.0.0-beta.1",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"import": "./dist/index.mjs"
|
|
8
|
+
"import": "./dist/index.mjs",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
9
10
|
}
|
|
10
11
|
},
|
|
11
|
-
"main": "./dist/index.
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
12
14
|
"types": "./dist/index.d.ts",
|
|
13
15
|
"files": [
|
|
14
16
|
"dist"
|
|
15
17
|
],
|
|
16
18
|
"peerDependencies": {
|
|
17
|
-
"
|
|
18
|
-
"vue": "
|
|
19
|
-
"vue-i18n": ">=9.0.0"
|
|
19
|
+
"vue": "^3.5.12",
|
|
20
|
+
"vue-i18n": "^10.0.4"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
-
"@vitejs/plugin-
|
|
25
|
-
"@vitejs/plugin-vue": "^
|
|
26
|
-
"
|
|
27
|
-
"boxen": "^
|
|
28
|
-
"chalk": "^5.
|
|
29
|
-
"consola": "^3.
|
|
30
|
-
"
|
|
31
|
-
"fast-glob": "^3.3.2",
|
|
32
|
-
"fs-extra": "^11.2.0",
|
|
23
|
+
"@pubinfo/unplugin-openapi": "^0.8.4",
|
|
24
|
+
"@vitejs/plugin-legacy": "^6.0.2",
|
|
25
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
26
|
+
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
|
27
|
+
"abort-controller": "^3.0.0",
|
|
28
|
+
"boxen": "^8.0.1",
|
|
29
|
+
"chalk": "^5.4.1",
|
|
30
|
+
"consola": "^3.4.0",
|
|
31
|
+
"fs-extra": "^11.3.0",
|
|
33
32
|
"jszip": "^3.10.1",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"unplugin-
|
|
38
|
-
"unplugin-
|
|
39
|
-
"
|
|
40
|
-
"unplugin-vue-components": "^0.27.2",
|
|
41
|
-
"vite-plugin-banner": "^0.7.1",
|
|
33
|
+
"terser": "^5.39.0",
|
|
34
|
+
"unocss": "^65.5.0",
|
|
35
|
+
"unplugin-auto-import": "^19.1.1",
|
|
36
|
+
"unplugin-icons": "^22.1.0",
|
|
37
|
+
"unplugin-vue-components": "^28.4.1",
|
|
38
|
+
"vite": "^6.2.0",
|
|
42
39
|
"vite-plugin-compression": "^0.5.1",
|
|
43
|
-
"vite-plugin-env-runtime": "^0.3.
|
|
44
|
-
"vite-plugin-fake-server": "^2.
|
|
45
|
-
"vite-plugin-
|
|
46
|
-
"vite-plugin-svg-icons": "^2.0.1",
|
|
47
|
-
"vite-plugin-vue-devtools": "^7.3.5"
|
|
40
|
+
"vite-plugin-env-runtime": "^0.3.6",
|
|
41
|
+
"vite-plugin-fake-server": "^2.2.0",
|
|
42
|
+
"vite-plugin-vue-devtools": "^7.7.2"
|
|
48
43
|
},
|
|
49
44
|
"devDependencies": {
|
|
50
45
|
"@types/fs-extra": "^11.0.4",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"vue": "^3.
|
|
54
|
-
"vue-i18n": "^
|
|
46
|
+
"@types/node": "^22.13.9",
|
|
47
|
+
"unbuild": "^3.5.0",
|
|
48
|
+
"vue": "^3.5.13",
|
|
49
|
+
"vue-i18n": "^10.0.5"
|
|
55
50
|
},
|
|
56
51
|
"scripts": {
|
|
57
|
-
"clean": "pnpm rimraf node_modules dist .turbo",
|
|
58
|
-
"build": "unbuild",
|
|
59
52
|
"stub": "unbuild --stub",
|
|
60
|
-
"
|
|
53
|
+
"build": "unbuild"
|
|
61
54
|
}
|
|
62
55
|
}
|