1 Star 0 Fork 10

Oo小刚oO/v3-electron-vite

forked from un-pany/v3-electron-vite 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
vite.config.mts 3.33 KB
一键复制 编辑 原始数据 按行查看 历史
pany-ang 提交于 2023-12-28 15:02 . chore: v4.3.0
import { defineConfig } from "vite"
import { resolve } from "path"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"
import svgLoader from "vite-svg-loader"
import UnoCSS from "unocss/vite"
import electron from "vite-electron-plugin"
import { rmSync } from "fs"
import pkg from "./package.json"
/** 清空 dist */
rmSync("dist", { recursive: true, force: true })
/** 配置项文档:https://cn.vitejs.dev/config */
export default defineConfig({
resolve: {
alias: {
/** @ 符号指向 src 目录 */
"@": resolve(__dirname, "./src")
}
},
server: {
/** 是否自动打开浏览器 */
open: false,
/** 设置 host: true 才可以使用 Network 的形式,以 IP 访问项目 */
host: pkg.env.host,
/** 端口号 */
port: pkg.env.port,
/** 预热常用文件,提高初始页面加载速度 */
warmup: {
clientFiles: ["./src/layouts/**/*.vue"]
}
},
build: {
/** 单个 chunk 文件的大小超过 2048KB 时发出警告 */
chunkSizeWarningLimit: 2048,
/** 禁用 gzip 压缩大小报告 */
reportCompressedSize: false,
rollupOptions: {
output: {
/**
* 分块策略
* 1. 注意这些包名必须存在,否则打包会报错
* 2. 如果你不想自定义 chunk 分割策略,可以直接移除这段配置
*/
manualChunks: {
vue: ["vue", "vue-router", "pinia"],
element: ["element-plus", "@element-plus/icons-vue"],
vxe: ["vxe-table", "vxe-table-plugin-element", "xe-utils"]
}
}
}
},
/** 混淆器 */
esbuild: {
/** 打包时移除 console.log */
pure: ["console.log"],
/** 打包时移除 debugger */
drop: ["debugger"],
/** 打包时移除所有注释 */
legalComments: "none"
},
/** Vite 插件 */
plugins: [
vue(),
vueJsx(),
/** 将 SVG 静态图转化为 Vue 组件 */
svgLoader({ defaultImport: "url" }),
/** SVG 插件 */
createSvgIconsPlugin({
// Specify the icon folder to be cached
iconDirs: [resolve(process.cwd(), "./src/icons/svg")],
// Specify symbolId format
symbolId: "icon-[dir]-[name]",
inject: "body-first"
}),
/** UnoCSS */
UnoCSS(),
electron({
outDir: "dist",
include: ["script"],
transformOptions: { sourcemap: false },
plugins: [
{
name: "remove-comments",
transform: ({ code }) => {
let content = code
// 匹配 块级注释、行级注释、Region注释
// \s 是匹配所有空白符, 包括换行; \S 非空白符, 不包括换行
const pattern1 = /\/\*[\s\S]*?\*\/|(\s)+\/\/[\s\S]*?[\n]+/g
content = content.replaceAll(pattern1, "\n")
// 匹配 所有空行
const pattern2 = /^\s*[\r\n]/gm
content = content.replaceAll(pattern2, "")
return content
}
}
]
})
],
css: {
postcss: {
plugins: [
{
postcssPlugin: "internal:charset-removal",
AtRule: {
charset: (atRule) => {
if (atRule.name === "charset") {
atRule.remove()
}
}
}
}
]
}
},
clearScreen: false
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/coolwhg/v3-electron-vite.git
git@gitee.com:coolwhg/v3-electron-vite.git
coolwhg
v3-electron-vite
v3-electron-vite
master

搜索帮助