| | |
| | | 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); |
| | |
| | | type: "app", |
| | | proxy, |
| | | }), |
| | | shortenMpWeixinFonts(), |
| | | ], |
| | | server: { |
| | | port: 9900, |