@dlzn-ui/vite-config 1.63.0 → 1.65.0

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.
@@ -0,0 +1,13 @@
1
+ import { ConfigEnv, UserConfig } from 'vite';
2
+ import AutoImport from 'unplugin-auto-import/vite';
3
+
4
+ type Arrayable<T> = Array<T> | T;
5
+ interface Options {
6
+ autoImportResolvers?: Array<UnwrapArrayable<UnwrapArrayable<NonNullable<Parameters<typeof AutoImport>[0]['resolvers']>>>>;
7
+ autoImports?: Array<NonNullable<UnwrapArrayable<Parameters<typeof AutoImport>[0]['imports']>>>;
8
+ root: string;
9
+ }
10
+ type UnwrapArrayable<T> = T extends Arrayable<infer U> ? U : never;
11
+ declare const _default: (_env: ConfigEnv, options: Options) => UserConfig;
12
+
13
+ export { _default as default };
@@ -0,0 +1,13 @@
1
+ import { ConfigEnv, UserConfig } from 'vite';
2
+ import AutoImport from 'unplugin-auto-import/vite';
3
+
4
+ type Arrayable<T> = Array<T> | T;
5
+ interface Options {
6
+ autoImportResolvers?: Array<UnwrapArrayable<UnwrapArrayable<NonNullable<Parameters<typeof AutoImport>[0]['resolvers']>>>>;
7
+ autoImports?: Array<NonNullable<UnwrapArrayable<Parameters<typeof AutoImport>[0]['imports']>>>;
8
+ root: string;
9
+ }
10
+ type UnwrapArrayable<T> = T extends Arrayable<infer U> ? U : never;
11
+ declare const _default: (_env: ConfigEnv, options: Options) => UserConfig;
12
+
13
+ export { _default as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,608 @@
1
+ import path, { basename, resolve, posix } from 'node:path';
2
+ import AutoImport from 'unplugin-auto-import/vite';
3
+ import ElementPlus from 'unplugin-element-plus/vite';
4
+ import Components from 'unplugin-vue-components/vite';
5
+ import { loadEnv, mergeConfig } from 'vite';
6
+ import { parseLoadedEnv } from 'vite-plugin-env-parse';
7
+ import { createHtmlPlugin } from 'vite-plugin-html';
8
+ import VueRouter from 'vue-router/vite';
9
+ import { globSync } from 'tinyglobby';
10
+ import { upperFirst } from '@dlzn-ui/node-utils';
11
+ import tailwindcss from '@tailwindcss/vite';
12
+ import vue from '@vitejs/plugin-vue';
13
+ import vueJsx from '@vitejs/plugin-vue-jsx';
14
+ import browserslist from 'browserslist';
15
+ import { browserslistToTargets } from 'lightningcss';
16
+ import tailwindAutoReference from 'vite-plugin-vue-tailwind-auto-reference';
17
+ import { TDesignResolver } from '@tdesign-vue-next/auto-import-resolver';
18
+ import { webUpdateNotice } from '@plugin-web-update-notification/vite';
19
+ import { visualizer } from 'rollup-plugin-visualizer';
20
+ import { compression } from 'vite-plugin-compression2';
21
+ import viteImagemin from 'vite-plugin-imagemin';
22
+ import fs from 'node:fs/promises';
23
+
24
+ const aliasElementPlus = (root) => {
25
+ const elementPlusCss = globSync("src/plugins/element-plus/theme-chalk/*.css", { cwd: root });
26
+ const arr = [];
27
+ elementPlusCss.forEach((file) => {
28
+ const _basename = basename(file);
29
+ arr.push({
30
+ find: `element-plus/theme-chalk/${_basename}`,
31
+ replacement: resolve(root, `src/plugins/element-plus/theme-chalk/${_basename}`)
32
+ });
33
+ });
34
+ return arr;
35
+ };
36
+
37
+ const autoImportStoreList = (root) => {
38
+ const piniaStoreKeys = [];
39
+ const files = globSync("src/store/modules/*.ts", { cwd: root });
40
+ files.forEach((p) => {
41
+ piniaStoreKeys.push(basename(p, ".ts"));
42
+ });
43
+ const customerImport = {};
44
+ piniaStoreKeys.forEach((key) => {
45
+ customerImport[`@/store/modules/${key}`] = [["default", `use${upperFirst(key)}Store`]];
46
+ });
47
+ return customerImport;
48
+ };
49
+
50
+ const baseConfigFn = (options) => {
51
+ const { tailwindAutoReferenceEntry } = options;
52
+ return {
53
+ clearScreen: false,
54
+ // 设为 false 可以避免 Vite 清屏而错过在终端中打印某些关键信息
55
+ css: {
56
+ lightningcss: {
57
+ // https://cn.vitejs.dev/config/shared-options#css-lightningcss
58
+ targets: browserslistToTargets(browserslist(">= 0.25%"))
59
+ },
60
+ transformer: "lightningcss"
61
+ // 开发/构建时怎么转译 CSS
62
+ },
63
+ plugins: [
64
+ tailwindAutoReference(tailwindAutoReferenceEntry),
65
+ // It must be registered before tailwindcss() official plugin!
66
+ tailwindcss(),
67
+ vue({
68
+ // features: {
69
+ // optionsAPI: false, // 不能删掉,tdesign 内部使用到了
70
+ // },
71
+ }),
72
+ vueJsx()
73
+ ]
74
+ };
75
+ };
76
+
77
+ const tDesignAutoImportResolve = (options) => {
78
+ const { isProduction, root } = options;
79
+ const tDesignResetComponentsSubFolderFiles = globSync("src/components/tDesignReset/*/Index.vue", {
80
+ cwd: root
81
+ });
82
+ const tDesignResetComponentsSubFolderName = tDesignResetComponentsSubFolderFiles.map((file) => {
83
+ return path.basename(path.dirname(file));
84
+ });
85
+ const autoImportComponentsSubFolderFiles = globSync("src/components/autoImport/*/Index.vue", {
86
+ cwd: root
87
+ });
88
+ const autoImportComponentsSubFolderName = autoImportComponentsSubFolderFiles.map((file) => {
89
+ return path.basename(path.dirname(file));
90
+ });
91
+ return [
92
+ {
93
+ resolve: (name) => {
94
+ if (["TCard"].includes(name)) {
95
+ return {
96
+ from: "dlzn-ui",
97
+ name
98
+ };
99
+ }
100
+ if (["Icon", "TBaseTable", "TDateRangePicker", "TEnhancedTable", "TPrimaryTable"].includes(
101
+ name
102
+ )) {
103
+ return;
104
+ }
105
+ if (tDesignResetComponentsSubFolderName.includes(name)) {
106
+ return {
107
+ from: `@/components/tDesignReset/${name}/Index.vue`,
108
+ name: "default"
109
+ };
110
+ }
111
+ if (autoImportComponentsSubFolderName.includes(name)) {
112
+ return {
113
+ from: `@/components/autoImport/${name}/Index.vue`,
114
+ name: "default"
115
+ };
116
+ }
117
+ if (tDesignResetComponentsSubFolderName.map((n) => {
118
+ const sliceName = n.slice(1);
119
+ return `_${sliceName === "Table" ? "EnhancedTable" : sliceName}`;
120
+ }).includes(name)) {
121
+ return {
122
+ as: name,
123
+ from: isProduction ? "tdesign-vue-next" : "@/plugins/tdesign-vue-next-for-dev",
124
+ name: name.slice(1)
125
+ };
126
+ }
127
+ const result = TDesignResolver({
128
+ library: "vue-next",
129
+ resolveIcons: false
130
+ // 禁用 https://tdesign.tencent.com/icons TDesign 图标独立站点 的图标
131
+ }).resolve(name);
132
+ if (result !== void 0) {
133
+ return {
134
+ from: isProduction ? result.from : "@/plugins/tdesign-vue-next-for-dev",
135
+ name: result.name
136
+ };
137
+ }
138
+ },
139
+ type: "component"
140
+ },
141
+ {
142
+ resolve: (name) => {
143
+ if (name === "Loading") {
144
+ return {
145
+ from: isProduction ? "tdesign-vue-next" : "@/plugins/tdesign-vue-next-for-dev",
146
+ name: "LoadingDirective"
147
+ };
148
+ }
149
+ },
150
+ type: "directive"
151
+ }
152
+ ];
153
+ };
154
+
155
+ const ENDPOINT = "/__dev__/save-folder-alias";
156
+ const OUTPUT_FILE_WATCH_IGNORE = "**/folder-alias.json";
157
+ const SKIP_COMPONENTS = /* @__PURE__ */ new Set(["Layout", "ParentView"]);
158
+ function devSaveFolderAlias(root) {
159
+ const OUTPUT_FILE = resolve(root, "folder-alias.json");
160
+ return {
161
+ apply: "serve",
162
+ // Vite 对插件 config() 的返回值会做深度合并(mergeConfig)
163
+ // 交给 chokidar ignored,避免写入触发 HMR / 整页重载
164
+ config() {
165
+ return {
166
+ server: {
167
+ watch: {
168
+ ignored: [OUTPUT_FILE_WATCH_IGNORE]
169
+ }
170
+ }
171
+ };
172
+ },
173
+ configureServer(server) {
174
+ server.middlewares.use(ENDPOINT, (req, res, next) => {
175
+ void handleSaveFolderAlias(req, res, next, server, OUTPUT_FILE);
176
+ });
177
+ },
178
+ name: "dev-save-folder-alias"
179
+ };
180
+ }
181
+ async function handleSaveFolderAlias(req, res, next, server, outPutFilePath) {
182
+ try {
183
+ const body = await readBody(req);
184
+ const data = JSON.parse(body);
185
+ const content = `${JSON.stringify(toFolderAlias(data), null, 2)}
186
+ `;
187
+ const resSuccess = () => {
188
+ res.statusCode = 200;
189
+ res.setHeader("Content-Type", "application/json");
190
+ res.end(JSON.stringify({ file: outPutFilePath, ok: true }));
191
+ };
192
+ try {
193
+ const prev = await fs.readFile(outPutFilePath, "utf8");
194
+ if (prev === content) {
195
+ resSuccess();
196
+ return;
197
+ }
198
+ } catch {
199
+ }
200
+ await fs.writeFile(outPutFilePath, content, "utf8");
201
+ server.config.logger.info(`[dev-save-folder-alias] written \u2192 ${outPutFilePath}`);
202
+ resSuccess();
203
+ } catch (error) {
204
+ const message = error instanceof Error ? error.message : String(error);
205
+ res.statusCode = 500;
206
+ res.setHeader("Content-Type", "application/json");
207
+ res.end(JSON.stringify({ message, ok: false }));
208
+ server.config.logger.error(`[dev-save-folder-alias] ${message}`);
209
+ }
210
+ }
211
+ function readBody(req) {
212
+ return new Promise((resolve2, reject) => {
213
+ const chunks = [];
214
+ req.setEncoding("utf8");
215
+ req.on("data", (chunk) => {
216
+ chunks.push(chunk);
217
+ });
218
+ req.on("end", () => {
219
+ resolve2(chunks.join(""));
220
+ });
221
+ req.on("error", reject);
222
+ });
223
+ }
224
+ function toFolderAlias(routers) {
225
+ const result = {};
226
+ const walk = (items, level = 0) => {
227
+ for (const item of items) {
228
+ const title = item.meta.title;
229
+ if (title !== "") {
230
+ const component = item.component;
231
+ if (!SKIP_COMPONENTS.has(component)) {
232
+ result[`src/views/${component.split("___")[0]}.vue`] = { description: title };
233
+ const arr = component.split("/");
234
+ arr.forEach((_, index) => {
235
+ if (index === arr.length - 1) {
236
+ return;
237
+ }
238
+ const key = `src/views/${arr.slice(0, index + 1).join("/")}`;
239
+ const description = [
240
+ ...new Set([result[key]?.description, title].filter(Boolean))
241
+ ].join("\u3001");
242
+ result[key] = {
243
+ description: index === 0 ? routers.find((r) => r.path === arr[0])?.meta.title ?? description : description
244
+ };
245
+ });
246
+ }
247
+ }
248
+ if (item.children !== void 0 && item.children.length > 0) {
249
+ walk(item.children, level + 1);
250
+ }
251
+ }
252
+ };
253
+ walk(routers);
254
+ return result;
255
+ }
256
+
257
+ const vitePlugins = (options) => {
258
+ const { isProduction, root } = options;
259
+ if (isProduction) {
260
+ return [
261
+ viteImagemin({
262
+ gifsicle: {
263
+ // https://github.com/imagemin/imagemin-gifsicle
264
+ colors: 256,
265
+ // 指定 GIF 图像调色板(颜色表)的最大颜色数量, 可丢弃一些颜色达到更大的优化效果
266
+ interlaced: false,
267
+ // 渐进式加载效果
268
+ optimizationLevel: 2
269
+ // 中的优化级别
270
+ },
271
+ mozjpeg: {
272
+ quality: 50
273
+ // 图片质量(0-100)
274
+ },
275
+ optipng: {
276
+ optimizationLevel: 3
277
+ // 压缩过程中尝试的优化策略和强度(0-7)
278
+ },
279
+ pngquant: {
280
+ quality: [0.65, 0.8],
281
+ // 压缩后的图片质量范围[最小, 最大]
282
+ speed: 4
283
+ },
284
+ svgo: {
285
+ datauri: "base64",
286
+ // 'base64'|'enc'|'unenc' 指定如何将 SVG 转换为 Data URI 格式
287
+ js2svg: {
288
+ // 控制 SVG 输出的格式
289
+ indent: 4,
290
+ // 缩进空格数
291
+ pretty: false
292
+ // 是否美化输出格式
293
+ },
294
+ multipass: false,
295
+ // 是否启用多遍优化: false 表示只进行单遍优化,true 会重复优化直到无法进一步优化, 设置为 true 的话可能优化的更大
296
+ plugins: [
297
+ {
298
+ name: "preset-default"
299
+ }
300
+ ]
301
+ },
302
+ webp: {
303
+ quality: 80
304
+ // 图片质量(0-100)
305
+ }
306
+ }),
307
+ compression(),
308
+ visualizer({
309
+ filename: "node_modules/.cache/visualizer/report.html",
310
+ open: true
311
+ }),
312
+ webUpdateNotice({
313
+ hiddenDefaultNotification: true,
314
+ logVersion: false
315
+ })
316
+ ];
317
+ } else {
318
+ return [
319
+ // vueDevTools()
320
+ {
321
+ configureServer(server) {
322
+ const { printUrls } = server;
323
+ server.printUrls = () => {
324
+ if (server.resolvedUrls !== null) {
325
+ server.resolvedUrls.local = [];
326
+ server.resolvedUrls.network = server.resolvedUrls.network.filter(
327
+ (url) => url.includes("192.168.")
328
+ );
329
+ }
330
+ printUrls();
331
+ };
332
+ },
333
+ name: "filter-vite-server-urls"
334
+ },
335
+ devSaveFolderAlias(root)
336
+ ];
337
+ }
338
+ };
339
+
340
+ function bypass(req, res, options) {
341
+ if (req.url !== void 0 && options.rewrite !== void 0 && typeof options.target === "string" && res !== void 0) {
342
+ const reqUrl = req.url;
343
+ const proxyUrl = new URL(options.rewrite(reqUrl), options.target).href;
344
+ res.setHeader("X-Res-ProxyUrl", proxyUrl);
345
+ }
346
+ }
347
+ function needPort(target) {
348
+ return target.startsWith("http://192.");
349
+ }
350
+ const index = (_env, options) => {
351
+ const { command, mode } = _env;
352
+ const resolvePath = (p) => resolve(options.root, p);
353
+ const envDir = "env";
354
+ const env = parseLoadedEnv(loadEnv(mode, envDir));
355
+ const {
356
+ VITE_API_PROXY_PORT_ARRAY,
357
+ VITE_APP_ID,
358
+ VITE_APP_NAME = "",
359
+ VITE_BASE_URL = "/",
360
+ VITE_FORCE_PWD_CHANGE = true,
361
+ VITE_PROXY_TARGET: viteProxyTarget,
362
+ VITE_USE_LOGIN_CAPTCHA = true
363
+ } = env;
364
+ const VITE_PROXY_TARGET = Array.isArray(viteProxyTarget) ? viteProxyTarget : [viteProxyTarget];
365
+ console.log({
366
+ command,
367
+ mode,
368
+ VITE_API_PROXY_PORT_ARRAY,
369
+ VITE_APP_ID,
370
+ VITE_APP_NAME,
371
+ VITE_BASE_URL,
372
+ VITE_FORCE_PWD_CHANGE,
373
+ VITE_PROXY_TARGET,
374
+ VITE_USE_LOGIN_CAPTCHA
375
+ });
376
+ const isProduction = mode === "production";
377
+ const getProxyTarget = (index, port) => {
378
+ const target = VITE_PROXY_TARGET.length > 1 ? VITE_PROXY_TARGET[index] : VITE_PROXY_TARGET[0];
379
+ return needPort(target) ? `${target}:${port}` : target;
380
+ };
381
+ return mergeConfig(
382
+ baseConfigFn({
383
+ tailwindAutoReferenceEntry: "node_modules/dlzn-ui/assets/css/tailwindcss-entry.css"
384
+ }),
385
+ {
386
+ build: {
387
+ rolldownOptions: {
388
+ output: {
389
+ minify: {
390
+ codegen: true,
391
+ //
392
+ compress: {
393
+ dropConsole: true
394
+ // 默认 false
395
+ // dropDebugger: true, // 默认 true
396
+ },
397
+ mangle: true
398
+ // 变量名混淆
399
+ }
400
+ }
401
+ }
402
+ },
403
+ define: {
404
+ VITE_API_PREFIX_ARRAY: JSON.stringify(VITE_API_PROXY_PORT_ARRAY.map(([prefix]) => prefix)),
405
+ VITE_APP_ID: JSON.stringify(VITE_APP_ID),
406
+ VITE_APP_NAME: JSON.stringify(VITE_APP_NAME),
407
+ VITE_BASE_URL: JSON.stringify(VITE_BASE_URL),
408
+ VITE_FORCE_PWD_CHANGE: JSON.stringify(VITE_FORCE_PWD_CHANGE),
409
+ VITE_USE_LOGIN_CAPTCHA: JSON.stringify(VITE_USE_LOGIN_CAPTCHA)
410
+ },
411
+ // envDir, // 将 env 文件里面的变量注入到 import.meta.env 里面
412
+ optimizeDeps: {
413
+ include: [
414
+ "tdesign-vue-next/dist/tdesign.min.js",
415
+ "path-browserify",
416
+ "lodash-es",
417
+ "pinia-plugin-persistedstate",
418
+ "alova",
419
+ "alova/fetch",
420
+ "alova/vue",
421
+ "@iconify/vue",
422
+ "@formkit/auto-animate",
423
+ "@formkit/auto-animate/vue",
424
+ "dayjs",
425
+ "dayjs/plugin/customParseFormat.js",
426
+ "dayjs/plugin/isSameOrBefore.js",
427
+ "dayjs/plugin/timezone.js",
428
+ "dayjs/plugin/utc.js",
429
+ "wordcloud",
430
+ "echarts/charts",
431
+ "echarts/components",
432
+ "echarts/core",
433
+ "echarts/renderers",
434
+ "@tdesign-vue-next/chat",
435
+ "vue-echarts",
436
+ "dompurify",
437
+ "cron-parser",
438
+ "cronstrue",
439
+ "cronstrue/locales/zh_CN",
440
+ "quartzcron",
441
+ "@bprogress/core",
442
+ "element-plus",
443
+ "element-plus/es/components/config-provider/style/css",
444
+ "element-plus/es/locale/lang/zh-cn",
445
+ "element-plus/es/components/date-picker/style/css",
446
+ "element-plus/es/components/scrollbar/style/css",
447
+ "color",
448
+ "dlzn-ui"
449
+ ]
450
+ },
451
+ plugins: [
452
+ // envParse({
453
+ // dtsPath: 'types/env.d.ts',
454
+ // }),
455
+ createHtmlPlugin({
456
+ entry: `/src/main.${isProduction ? "prod" : "dev"}.ts`,
457
+ // 必须绝对路径,否则类似system/log/operlog 二级页面打不开
458
+ inject: {
459
+ data: {
460
+ appId: VITE_APP_ID,
461
+ mode: isProduction ? "prod" : "dev",
462
+ title: VITE_APP_NAME
463
+ },
464
+ ejsOptions: {
465
+ views: ["node_modules/dlzn-ui/ejs"]
466
+ }
467
+ },
468
+ minify: true,
469
+ // 相对消费方 root,closeBundle 整理 HTML 时比绝对路径更稳
470
+ template: "node_modules/dlzn-ui/index.html"
471
+ }),
472
+ VueRouter({
473
+ dts: "types/typed-router.d.ts"
474
+ }),
475
+ ElementPlus({}),
476
+ AutoImport({
477
+ // 用于自动导入 函数/工具库 的 API
478
+ // function modifyDefaultExportsAlias(imports, options) {
479
+ // if (options.defaultExportByFilename) imports.forEach((i) => {
480
+ // if (i.name === "default") i.as = i.from.split("/").pop()?.split(".")?.shift() ?? i.as;
481
+ // });
482
+ // return imports;
483
+ // }
484
+ // defaultExportByFilename: false, // 默认为 false
485
+ dirs: ["src/plugins/autoImport", "src/bus/autoImport", "src/hooks"],
486
+ dirsScanOptions: {
487
+ types: false
488
+ // Enable auto import the types under the directories
489
+ },
490
+ dts: "types/auto-imports.d.ts",
491
+ // dtsMode: 'overwrite', // overwrite the whole existing .d.ts file with the new type definitions.
492
+ imports: [
493
+ "vue",
494
+ "vue-router",
495
+ "pinia",
496
+ "@vueuse/core",
497
+ {
498
+ from: "alova/client",
499
+ imports: ["useRequest", "useWatcher", "usePagination"]
500
+ },
501
+ {
502
+ from: "@/plugins/others/directive.ts",
503
+ imports: ["checkPermissions"]
504
+ },
505
+ {
506
+ from: "dlzn-ui/utils",
507
+ imports: ["formatNumber", "isFalsy", "stringDisplay"]
508
+ },
509
+ {
510
+ "@/plugins/alova/index.ts": [["default", "alovaInst"]]
511
+ },
512
+ {
513
+ from: "@/components/tDesignReset/TForm/index.ts",
514
+ imports: ["FormItem", "FormInstance", "FormExposed"],
515
+ type: true
516
+ },
517
+ {
518
+ from: "@/components/tDesignReset/TTable/index.ts",
519
+ imports: ["TableCol", "CellRenderContext"],
520
+ type: true
521
+ },
522
+ {
523
+ from: "@/components/autoImport/TPageList/index.ts",
524
+ imports: ["PageListProps"],
525
+ type: true
526
+ },
527
+ autoImportStoreList(options.root),
528
+ ...options.autoImports ?? []
529
+ ],
530
+ resolvers: [
531
+ ...options.autoImportResolvers ?? [],
532
+ ...tDesignAutoImportResolve({
533
+ isProduction,
534
+ root: options.root
535
+ })
536
+ ],
537
+ vueTemplate: true
538
+ // 允许插件扫描 Vue 文件的 <template> 部分,并自动导入在模板表达式中使用的 API
539
+ }),
540
+ Components({
541
+ deep: false,
542
+ // 用于自动导入 Vue 组件
543
+ dts: "types/components.d.ts",
544
+ resolvers: [
545
+ ...options.autoImportResolvers ?? [],
546
+ ...tDesignAutoImportResolve({
547
+ isProduction,
548
+ root: options.root
549
+ })
550
+ ]
551
+ // syncMode: 'overwrite',
552
+ }),
553
+ ...vitePlugins({ isProduction, root: options.root })
554
+ ],
555
+ resolve: {
556
+ alias: [
557
+ {
558
+ find: "@",
559
+ replacement: resolvePath("src")
560
+ // 使用绝对路径(官方推荐)
561
+ },
562
+ {
563
+ find: "img",
564
+ // 路径以 img 开头
565
+ replacement: resolvePath("src/assets/images")
566
+ },
567
+ ...isProduction ? [] : [
568
+ {
569
+ // find 为正则时只替换匹配段,必须用 ^...$ 匹配完整 id
570
+ // 同时覆盖裸导入与已 resolve 的绝对路径
571
+ find: /^.*tdesign-vue-next[/\\]es[/\\].*\.css$/,
572
+ replacement: resolvePath("src/plugins/tdesign-vue-next-for-dev/empty.css")
573
+ }
574
+ ],
575
+ ...aliasElementPlus(options.root)
576
+ ],
577
+ // https://cn.vitejs.dev/guide/performance.html#reduce-resolve-operations
578
+ // 不建议忽略自定义导入类型的扩展名(例如:.vue),因为它会影响 IDE 和类型支持。
579
+ extensions: [".ts", ".mjs", ".js"]
580
+ // js 和 mjs 打包chat包时需要
581
+ },
582
+ root: options.root,
583
+ server: {
584
+ // vite preview 也会走该代理
585
+ host: "0.0.0.0",
586
+ // 可以用ip访问
587
+ open: false,
588
+ port: VITE_API_PROXY_PORT_ARRAY[0][1] + 1e3,
589
+ proxy: Object.fromEntries(
590
+ VITE_API_PROXY_PORT_ARRAY.map(([prefix, port], index) => [
591
+ `${posix.join(VITE_BASE_URL, prefix)}/`,
592
+ {
593
+ bypass,
594
+ changeOrigin: true,
595
+ rewrite: (p) => {
596
+ return VITE_BASE_URL === "/" ? p : p.replace(new RegExp(VITE_BASE_URL), "");
597
+ },
598
+ target: getProxyTarget(index, port)
599
+ }
600
+ ])
601
+ ),
602
+ strictPort: true
603
+ }
604
+ }
605
+ );
606
+ };
607
+
608
+ export { index as default };
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@dlzn-ui/vite-config",
3
3
  "type": "module",
4
- "version": "1.63.0",
4
+ "version": "1.65.0",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "exports": {
10
10
  ".": {
11
- "import": "./index.ts"
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs"
12
13
  }
13
14
  },
15
+ "files": [
16
+ "dist"
17
+ ],
14
18
  "peerDependencies": {
15
19
  "tailwindcss": "^4.3.3",
16
20
  "vite": "^8.2.0"
@@ -33,6 +37,15 @@
33
37
  "vite-plugin-imagemin": "^0.6.1",
34
38
  "vite-plugin-vue-tailwind-auto-reference": "^2.0.2",
35
39
  "vue-router": "^5.2.0",
36
- "@dlzn-ui/node-utils": "1.63.0"
40
+ "@dlzn-ui/node-utils": "1.65.0"
41
+ },
42
+ "devDependencies": {
43
+ "rimraf": "^6.1.3",
44
+ "unbuild": "^3.6.1"
45
+ },
46
+ "scripts": {
47
+ "build": "unbuild",
48
+ "clean": "rimraf dist",
49
+ "stub": "unbuild --stub"
37
50
  }
38
51
  }
@@ -1,20 +0,0 @@
1
- import { basename, resolve } from 'node:path'
2
- import { globSync } from 'tinyglobby'
3
-
4
- export default (root: string) => {
5
- const elementPlusCss = globSync('src/plugins/element-plus/theme-chalk/*.css', { cwd: root })
6
- const arr: Array<{
7
- find: string
8
- replacement: string
9
- }> = []
10
-
11
- elementPlusCss.forEach((file) => {
12
- const _basename = basename(file)
13
-
14
- arr.push({
15
- find: `element-plus/theme-chalk/${_basename}`,
16
- replacement: resolve(root, `src/plugins/element-plus/theme-chalk/${_basename}`),
17
- })
18
- })
19
- return arr
20
- }