@pubinfo/vite 0.6.10 → 2.0.0-beta.2

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 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
+ });
@@ -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 vite from 'vite';
1
+ import * as _pubinfo_unplugin_openapi from '@pubinfo/unplugin-openapi';
2
+ import { Options } from '@pubinfo/unplugin-openapi';
2
3
  import { UserConfig, UserConfigFnObject } from 'vite';
4
+ export * from 'vite';
3
5
 
4
- declare function defineConfig(defineOptions?: UserConfig | UserConfigFnObject): vite.UserConfigExport;
6
+ interface PubinfoConfig {
7
+ /** `vite` */
8
+ vite?: UserConfig | UserConfigFnObject;
9
+ /** `@pubinfo/unplugin-openapi` */
10
+ openapi?: Options;
11
+ }
5
12
 
6
- export { defineConfig };
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
-
2
- /// <reference types="@intlify/unplugin-vue-i18n/messages" />
3
- /// <reference types="unplugin-icons/types/vue" />
4
-
5
- import * as vite from 'vite';
1
+ import * as _pubinfo_unplugin_openapi from '@pubinfo/unplugin-openapi';
2
+ import { Options } from '@pubinfo/unplugin-openapi';
6
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
+ }
7
12
 
8
- declare function defineConfig(defineOptions?: UserConfig | UserConfigFnObject): vite.UserConfigExport;
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
+ };
9
27
 
10
- export { defineConfig };
28
+ export { defineModuleConfig, definePubinfoConfig };
package/dist/index.mjs CHANGED
@@ -1,66 +1,58 @@
1
- import path, { resolve as resolve$1 } from 'node:path';
2
- import process from 'node:process';
3
- import { defineConfig as defineConfig$1, loadEnv, mergeConfig } from 'vite';
4
- import fs from 'node:fs/promises';
5
- import { readPackageJSON } from 'pkg-types';
6
- import dayjs from 'dayjs';
7
- import consola from 'consola';
1
+ import { loadEnv, defineConfig, mergeConfig } from 'vite';
2
+ export * from 'vite';
3
+ import { cwd } from 'node:process';
8
4
  import chalk from 'chalk';
9
- import vueLegacy from '@vitejs/plugin-legacy';
5
+ import consola from 'consola';
6
+ import { createRequire } from 'node:module';
7
+ import { join, resolve } from 'node:path';
10
8
  import vue from '@vitejs/plugin-vue';
11
9
  import vueJsx from '@vitejs/plugin-vue-jsx';
12
10
  import autoImport from 'unplugin-auto-import/vite';
13
- import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
14
11
  import IconsResolver from 'unplugin-icons/resolver';
15
- import banner from 'vite-plugin-banner';
12
+ import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
16
13
  import components from 'unplugin-vue-components/vite';
17
14
  import compression from 'vite-plugin-compression';
18
- import TurboConsole from 'unplugin-turbo-console/vite';
19
- import vueI18n from '@intlify/unplugin-vue-i18n/vite';
20
- import { existsSync } from 'node:fs';
21
- import { vitePluginFakeServer } from 'vite-plugin-fake-server';
22
- import fg from 'fast-glob';
23
- import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
24
- import Unocss from 'unocss/vite';
25
15
  import Icons from 'unplugin-icons/vite';
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 boxen from 'boxen';
22
+ import Unocss from 'unocss/vite';
29
23
 
30
- function cleanse() {
24
+ function alias(root) {
25
+ const resolvePath = (name) => join(root, name);
26
+ const resolveDeps = (name, path) => join(createRequire(import.meta.url).resolve(name), path);
31
27
  return {
32
- name: "esbuild-plugin-cleanse",
33
- setup(build) {
34
- build.onLoad({ filter: /\/dist\/alova\.esm\.js$/ }, async (args) => {
35
- let alovaContnet = await fs.readFile(args.path, "utf-8");
36
- alovaContnet = alovaContnet.replace(/\/\* c8 ignore start \*\/[\s\S]*?\/\* c8 ignore stop \*\//g, "");
37
- return {
38
- contents: `${alovaContnet}`
39
- };
40
- });
41
- }
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", "../")
42
52
  };
43
53
  }
44
54
 
45
- async function createDefineSystemInfo(root) {
46
- try {
47
- const pkgJson = await readPackageJSON(root);
48
- const { dependencies, devDependencies, version } = pkgJson;
49
- const lastBuildTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
50
- const SYSTEM_INFO = {
51
- pkg: {
52
- dependencies,
53
- devDependencies,
54
- version
55
- },
56
- lastBuildTime
57
- };
58
- return JSON.stringify(SYSTEM_INFO);
59
- } catch (error) {
60
- return "";
61
- }
62
- }
63
- function getServerProxy(env, isProxy, rewrite = true) {
55
+ function getServerProxy(env, isProxy) {
64
56
  if (!isProxy) {
65
57
  return {};
66
58
  }
@@ -76,113 +68,47 @@ function getServerProxy(env, isProxy, rewrite = true) {
76
68
  } else {
77
69
  serverProxy[pk] = {
78
70
  target: url,
79
- changeOrigin: rewrite,
80
- rewrite: (path) => {
81
- return path.replace(pk, "");
82
- }
71
+ changeOrigin: true,
72
+ rewrite: (path) => path.replace(pk, ""),
73
+ secure: false
83
74
  };
84
75
  }
85
76
  }
86
77
  return serverProxy;
87
78
  }
88
79
 
89
- function resolve(name) {
90
- if (!name.startsWith("usePub")) {
91
- return;
92
- }
93
- return {
94
- name,
95
- from: "@pubinfo/composables"
96
- };
97
- }
98
- function PubInfoResolver$1() {
99
- return (name) => {
100
- return resolve(name);
101
- };
102
- }
103
-
104
80
  function createAutoImport() {
105
81
  return autoImport({
106
82
  imports: [
107
83
  "vue",
108
84
  "vue-router",
109
- "vue-i18n",
110
- "vitest",
85
+ // 'vue-i18n',
86
+ "pinia",
111
87
  {
112
- alova: [
113
- "useRequest",
114
- "invalidateCache"
88
+ pubinfo: [
89
+ "useAuth"
115
90
  ]
116
91
  }
117
92
  ],
93
+ // 解决代码混淆后出现的h和vue导入的h变量命名重复的问题
94
+ ignore: ["h"],
118
95
  dts: "./types/auto-imports.d.ts",
119
96
  dirs: [
120
- "./src/utils/composables/**",
121
- "./src/composables/**/*",
122
- "./src/api/modules/**/*.ts"
97
+ "./src/composables/**/*"
123
98
  ],
124
99
  resolvers: [
125
100
  AntDesignVueResolver(),
126
101
  IconsResolver({
127
102
  prefix: "i"
128
- }),
129
- PubInfoResolver$1()
103
+ })
130
104
  ]
131
105
  });
132
106
  }
133
107
 
134
- const deploymentTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
135
- function createBanner() {
136
- return banner(`
137
- /**
138
- * \u7531 \u793E\u4F1A\u6CBB\u7406\u4E8B\u4E1A\u90E8 \u63D0\u4F9B\u6280\u672F\u652F\u6301
139
- * Powered by wsy-admin
140
- * ${deploymentTime}
141
- */
142
- `);
143
- }
144
-
145
- function resolveComponent(componentName) {
146
- if (!componentName.match(/^Pub[A-Z]/)) {
147
- return;
148
- }
149
- return {
150
- name: componentName,
151
- as: componentName,
152
- from: "@pubinfo/components"
153
- };
154
- }
155
- function resolveDirective(directiveName) {
156
- if (!directiveName.match(/^Pub[A-Z]/)) {
157
- return;
158
- }
159
- return {
160
- name: directiveName,
161
- from: "@pubinfo/directives"
162
- };
163
- }
164
- function PubInfoResolver() {
165
- return [
166
- {
167
- type: "component",
168
- resolve: async (name) => {
169
- return resolveComponent(name);
170
- }
171
- },
172
- {
173
- type: "directive",
174
- resolve: async (name) => {
175
- return resolveDirective(name);
176
- }
177
- }
178
- ];
179
- }
180
-
181
108
  function createComponents() {
182
109
  return components({
183
110
  dirs: [
184
- "src/components",
185
- "src/layouts/ui-kit"
111
+ "src/components"
186
112
  ],
187
113
  directives: true,
188
114
  include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
@@ -192,7 +118,19 @@ function createComponents() {
192
118
  resolveIcons: true,
193
119
  importStyle: false
194
120
  }),
195
- PubInfoResolver()
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
+ }
196
134
  ],
197
135
  dts: "./types/components.d.ts"
198
136
  });
@@ -222,134 +160,14 @@ function createCompression(env) {
222
160
  return plugin;
223
161
  }
224
162
 
225
- function createConsole() {
226
- return TurboConsole({
227
- disableLaunchEditor: true
228
- });
229
- }
230
-
231
- function createI18n() {
232
- const root = process.cwd();
233
- const pathResolve = (pathname) => resolve$1(root, ".", pathname);
234
- return vueI18n({
235
- include: `${pathResolve("src")}/locales/lang/**`
236
- });
237
- }
238
-
239
- function createMock(env, isBuild) {
240
- const { VITE_BUILD_MOCK } = env;
241
- const root = process.cwd();
242
- if (!existsSync(resolve$1(root, "src/mock"))) {
243
- return;
244
- }
245
- return vitePluginFakeServer({
246
- logger: !isBuild,
247
- include: "src/mock",
248
- infixName: false,
249
- enableProd: isBuild && VITE_BUILD_MOCK === "true"
250
- });
251
- }
252
-
253
- var __defProp$1 = Object.defineProperty;
254
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
255
- var __publicField$1 = (obj, key, value) => {
256
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
257
- return value;
258
- };
259
- let Ctx$1 = class Ctx {
260
- constructor(options) {
261
- __publicField$1(this, "root");
262
- __publicField$1(this, "globs");
263
- __publicField$1(this, "sourcePath");
264
- __publicField$1(this, "path");
265
- this.globs = options.globs;
266
- }
267
- setRoot(root) {
268
- this.root = root;
269
- }
270
- searchGlob() {
271
- const { root, globs } = this;
272
- this.sourcePath = fg.sync(globs, {
273
- cwd: root,
274
- onlyFiles: true
275
- });
276
- this.normalizePath();
277
- }
278
- normalizePath() {
279
- const path = [];
280
- for (const f of this.sourcePath) {
281
- path.push(`@use "${f}" as *;`);
282
- }
283
- this.path = path.join("");
284
- }
285
- };
286
- function scssPreprocessor(options) {
287
- const ctx = new Ctx$1(options);
288
- return {
289
- name: "vite-plugin-scssPreprocessor",
290
- enforce: "pre",
291
- config: (config) => {
292
- ctx.setRoot(config.root);
293
- ctx.searchGlob();
294
- return {
295
- css: {
296
- preprocessorOptions: {
297
- scss: {
298
- additionalData: ctx.path
299
- }
300
- }
301
- }
302
- };
303
- }
304
- };
305
- }
306
- function createPreprocessor() {
307
- return scssPreprocessor({
308
- globs: ["src/assets/styles/resources/*.scss"]
309
- });
310
- }
311
-
312
- function createSvgIcon(isBuild) {
313
- return createSvgIconsPlugin({
314
- iconDirs: [path.resolve(process.cwd(), "src/assets/icons/")],
315
- symbolId: "icon-[dir]-[name]",
316
- svgoOptions: isBuild
317
- });
318
- }
319
-
320
- function createUnocss() {
321
- return Unocss();
322
- }
323
-
324
163
  function createIcons() {
325
164
  return Icons({
326
165
  autoInstall: false
327
166
  });
328
167
  }
329
168
 
330
- function createInspector(env) {
331
- const { VITE_APP_INSPECTOR } = env;
332
- if (VITE_APP_INSPECTOR && VITE_APP_INSPECTOR === "true") {
333
- return VueDevTools();
334
- } else {
335
- return null;
336
- }
337
- }
338
-
339
- function createOpenAPI() {
340
- return OpenAPI();
341
- }
342
-
343
- var __defProp = Object.defineProperty;
344
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
345
- var __publicField = (obj, key, value) => {
346
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
347
- return value;
348
- };
349
169
  class Ctx {
350
- constructor() {
351
- __publicField(this, "options");
352
- }
170
+ options;
353
171
  setOptions(options) {
354
172
  this.options = options;
355
173
  }
@@ -395,31 +213,61 @@ function appInfo() {
395
213
  };
396
214
  }
397
215
 
398
- function createVitePlugins(viteEnv, isBuild = false) {
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) {
399
260
  const vitePlugins = [
400
261
  vue(),
401
262
  vueJsx(),
402
- vueLegacy({
403
- modernPolyfills: [
404
- "es.array.at",
405
- "es.array.find-last"
406
- ],
407
- additionalLegacyPolyfills: ["abort-controller/polyfill"]
408
- }),
263
+ createLegacy(viteEnv),
409
264
  createAutoImport(),
410
265
  createComponents(),
411
266
  createUnocss(),
412
- createSvgIcon(isBuild),
413
267
  createIcons(),
414
- createI18n(),
415
268
  createMock(viteEnv, isBuild),
416
- createBanner(),
417
- createPreprocessor(),
418
- // createZip(),
419
- createConsole(),
420
269
  createInspector(viteEnv),
421
- createOpenAPI(),
422
- // createConfig(),
270
+ createOpenAPI(config.openapi),
423
271
  appInfo()
424
272
  ];
425
273
  const buildPlugins = () => [
@@ -431,11 +279,9 @@ function createVitePlugins(viteEnv, isBuild = false) {
431
279
  return vitePlugins.filter(Boolean);
432
280
  }
433
281
 
434
- function defineConfig(defineOptions = {}) {
435
- return defineConfig$1(async ({ mode, command }) => {
436
- const root = process.cwd();
437
- const pathResolve = (pathname) => resolve$1(root, ".", pathname);
438
- const __SYSTEM_INFO__ = await createDefineSystemInfo(root);
282
+ function createDefaultAppConfig(config) {
283
+ return ({ mode, command }) => {
284
+ const root = cwd();
439
285
  const isBuild = command === "build";
440
286
  const timestamp = (/* @__PURE__ */ new Date()).getTime();
441
287
  const env = loadEnv(mode, root);
@@ -447,46 +293,21 @@ function defineConfig(defineOptions = {}) {
447
293
  open: true,
448
294
  host: true,
449
295
  proxy: serverProxy,
450
- watch: {
451
- ignored: ["!**/node_modules/@pubinfo/themes/src/system/**/*"]
452
- },
453
296
  warmup: {
454
297
  clientFiles: [
455
- "./index.html",
456
- "./src/{layouts,components}/*",
457
- "./src/locales/**/*"
298
+ "./index.html"
458
299
  ]
459
300
  }
460
301
  },
461
- resolve: {
462
- alias: [
463
- {
464
- find: /@\//,
465
- replacement: `${pathResolve("src")}/`
466
- },
467
- {
468
- find: /#\//,
469
- replacement: `${pathResolve("types")}/`
470
- }
302
+ // To fix some dev problems
303
+ optimizeDeps: {
304
+ exclude: [
305
+ "pubinfo",
306
+ "@pubinfo/core"
471
307
  ]
472
308
  },
473
- optimizeDeps: {
474
- // include: [
475
- // 'ant-design-vue/es/locale/zh_CN',
476
- // 'ant-design-vue/es/locale/en_US',
477
- // '@ant-design/icons-vue',
478
- // 'dayjs',
479
- // 'dayjs/locale/eu',
480
- // 'dayjs/locale/zh-cn',
481
- // '@pubinfo/pro-components',
482
- // 'qrcode',
483
- // '@pubinfo/headlessui',
484
- // ],
485
- esbuildOptions: {
486
- plugins: [
487
- cleanse()
488
- ]
489
- }
309
+ resolve: {
310
+ alias: alias(root)
490
311
  },
491
312
  build: {
492
313
  outDir: mode === "production" ? "dist" : `dist-${mode}`,
@@ -496,27 +317,67 @@ function defineConfig(defineOptions = {}) {
496
317
  rollupOptions: {
497
318
  output: {
498
319
  entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`
499
- // manualChunks: {
500
- // vue: ['vue', 'pinia', 'vue-router'],
501
- // lodash: ['lodash-es'],
502
- // antd: ['ant-design-vue', '@ant-design/icons-vue'],
503
- // lottie: ['lottie-web'],
504
- // },
505
320
  }
506
321
  }
507
322
  },
508
- define: {
509
- __SYSTEM_INFO__,
510
- _DEV_: mode === "development",
511
- _PROD_: mode === "production"
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
+ ]
341
+ },
342
+ resolve: {
343
+ alias: alias(root)
512
344
  },
513
- plugins: createVitePlugins(env, isBuild)
345
+ build: {
346
+ rollupOptions: {
347
+ external: [
348
+ "vue",
349
+ "vue-router",
350
+ "pinia",
351
+ "unocss"
352
+ ]
353
+ }
354
+ },
355
+ plugins: createVitePlugins(env, isBuild, config)
514
356
  };
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 }) => {
515
376
  return mergeConfig(
516
- applicationConfig,
517
- typeof defineOptions === "function" ? defineOptions({ mode, command }) : defineOptions
377
+ defaultOptions({ mode, command }),
378
+ typeof viteOptions === "function" ? viteOptions({ mode, command }) : viteOptions
518
379
  );
519
380
  });
520
381
  }
521
382
 
522
- export { defineConfig };
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.6.10",
4
+ "version": "2.0.0-beta.2",
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.mjs",
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
- "vite": ">=5.0.0",
18
- "vue": ">=3.4.0",
19
- "vue-i18n": ">=9.0.0"
19
+ "vue": "^3.5.12",
20
+ "vue-i18n": "^10.0.4"
20
21
  },
21
22
  "dependencies": {
22
- "@intlify/unplugin-vue-i18n": "^4.0.0",
23
- "@pubinfo/unplugin-openapi": "^0.7.0",
24
- "@vitejs/plugin-legacy": "^5.4.2",
25
- "@vitejs/plugin-vue": "^5.1.4",
26
- "@vitejs/plugin-vue-jsx": "^4.0.1",
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
27
  "abort-controller": "^3.0.0",
28
28
  "boxen": "^8.0.1",
29
- "chalk": "^5.3.0",
30
- "consola": "^3.2.3",
31
- "dayjs": "^1.11.13",
32
- "fast-glob": "^3.3.2",
33
- "fs-extra": "^11.2.0",
29
+ "chalk": "^5.4.1",
30
+ "consola": "^3.4.0",
31
+ "fs-extra": "^11.3.0",
34
32
  "jszip": "^3.10.1",
35
- "pkg-types": "^1.2.0",
36
- "terser": "^5.31.6",
37
- "unocss": "^0.62.3",
38
- "unplugin-auto-import": "^0.18.2",
39
- "unplugin-icons": "^0.19.2",
40
- "unplugin-turbo-console": "^1.10.1",
41
- "unplugin-vue-components": "^0.27.4",
42
- "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",
43
39
  "vite-plugin-compression": "^0.5.1",
44
- "vite-plugin-env-runtime": "^0.3.5",
45
- "vite-plugin-fake-server": "^2.1.1",
46
- "vite-plugin-pages": "^0.32.3",
47
- "vite-plugin-svg-icons": "^2.0.1",
48
- "vite-plugin-vue-devtools": "^7.3.9"
40
+ "vite-plugin-env-runtime": "^0.3.6",
41
+ "vite-plugin-fake-server": "^2.2.0",
42
+ "vite-plugin-vue-devtools": "^7.7.2"
49
43
  },
50
44
  "devDependencies": {
51
45
  "@types/fs-extra": "^11.0.4",
52
- "vite": "^5.4.8",
53
- "vue": "^3.5.12",
54
- "vue-i18n": "^10.0.4"
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
- "lint": "eslint . --cache --fix"
53
+ "build": "unbuild"
61
54
  }
62
55
  }