1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| import uni from "@dcloudio/vite-plugin-uni"; // !此依赖不能安装
| import fs from "fs";
| import path from "path";
| import { defineConfig } from "vite";
| import { cool } from "@cool-vue/vite-plugin";
| import { proxy } from "./config/proxy";
|
| // 微信 WXSS 单行过长会编译失败。图标字体若同时内联 woff2/woff/ttf,会超过限制。
| function shortenMpWeixinFonts() {
| return {
| name: "mp-weixin-shorten-fonts",
| enforce: "post" as const,
| closeBundle() {
| const dirs = ["unpackage/dist/dev/mp-weixin", "unpackage/dist/build/mp-weixin"];
| for (const dir of dirs) {
| const file = path.resolve(__dirname, dir, "app.wxss");
| if (!fs.existsSync(file)) continue;
| const css = fs.readFileSync(file, "utf8");
| const next = css.replace(
| /src:\s*url\("data:font\/woff2;base64,[^"]+"\)\s*format\("woff2"\)\s*,\s*url\("data:font\/woff;base64,[^"]+"\)\s*format\("woff"\)\s*,\s*url\("data:font\/ttf;base64,[^"]+"\)\s*format\("truetype"\)/g,
| (block) => {
| const woff2 = block.match(
| /url\("data:font\/woff2;base64,[^"]+"\)\s*format\("woff2"\)/
| );
| return woff2 ? `src: ${woff2[0]}` : block;
| }
| );
| if (next !== css) fs.writeFileSync(file, next);
| }
| },
| };
| }
|
| function resolve(dir: string) {
| return path.resolve(__dirname, dir);
| }
|
| // https://vitejs.dev/config
|
| export default defineConfig(() => {
| return {
| plugins: [
| uni(),
| cool({
| type: "app",
| proxy,
| }),
| shortenMpWeixinFonts(),
| ],
| server: {
| port: 9900,
| proxy,
| hmr: {
| overlay: true,
| },
| },
| define: {
| __VUE_I18N_FULL_INSTALL__: true,
| __VUE_I18N_LEGACY_API__: true,
| __INTLIFY_PROD_DEVTOOLS__: false,
| },
| resolve: {
| alias: {
| "/@": resolve("./"),
| "/$": resolve("./uni_modules/"),
| },
| },
| };
| });
|
|