4 Star 0 Fork 0

zhangmeng/health_checkup

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.ts 3.71 KB
一键复制 编辑 原始数据 按行查看 历史
zhangmeng 提交于 2023-02-09 22:47 . 打印修改,表格高度
import { rmSync } from "node:fs";
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import electron from "vite-plugin-electron";
import renderer from "vite-plugin-electron-renderer";
import pkg from "./package.json";
import path, { resolve } from "path";
import DefineOptions from "unplugin-vue-define-options/vite";
// const VITE_APP_SERVER_URL: string = loadEnv(mode, process.cwd()).VITE_APP_SERVER_URL;
import { createHtmlPlugin } from "vite-plugin-html";
// https://vitejs.dev/config/
//这个配置 为了在html中使用 环境变量
const getViteEnv = (mode, target) => {
return loadEnv(mode, process.cwd())[target];
};
export default defineConfig(({ command, mode }) => {
rmSync("dist-electron", { recursive: true, force: true });
console.log("command", command);
const isServe = command === "serve";
const isBuild = command === "build";
const sourcemap = isServe || !!process.env.VSCODE_DEBUG;
console.log("mode", mode);
return {
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
},
},
plugins: [
vue(),
electron([
{
// Main-Process entry file of the Electron App.
entry: "electron/main/index.ts",
onstart(options) {
if (process.env.VSCODE_DEBUG) {
console.log(
/* For `.vscode/.debug.script.mjs` */ "[startup] Electron App"
);
} else {
options.startup();
}
},
vite: {
build: {
sourcemap,
minify: isBuild,
outDir: "dist-electron/main",
rollupOptions: {
external: Object.keys(
"dependencies" in pkg ? pkg.dependencies : {}
),
},
},
},
},
{
entry: "electron/preload/index.ts",
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
options.reload();
},
vite: {
build: {
sourcemap,
minify: isBuild,
outDir: "dist-electron/preload",
rollupOptions: {
external: Object.keys(
"dependencies" in pkg ? pkg.dependencies : {}
),
},
},
},
},
]),
// Use Node.js API in the Renderer-process
renderer({
nodeIntegration: true,
}),
DefineOptions(),
createHtmlPlugin({
inject: {
data: {
title: getViteEnv(mode, "VITE_APP_TITLE"),
},
},
}),
],
server:
process.env.VSCODE_DEBUG &&
(() => {
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL);
return {
host: url.hostname,
port: +url.port,
};
})(),
clearScreen: false,
build: {
/** 消除打包大小超过 500kb 警告 */
chunkSizeWarningLimit: 2000,
/** Vite 2.6.x 以上需要配置 minify: "terser", terserOptions 才能生效 */
minify: "terser",
sourcemap: "inline",
/** 在打包代码时移除 console.log、debugger 和 注释 */
terserOptions: {
compress: {
// drop_console: false,
drop_debugger: true,
// pure_funcs: ["console.log"],
},
format: {
/** 删除注释 */
comments: false,
},
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "./src/assets/style/global-variables.scss" as *;`,
},
},
},
};
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xmgcoding/health_checkup.git
git@gitee.com:xmgcoding/health_checkup.git
xmgcoding
health_checkup
health_checkup
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385