vite配置electron、ElementPlus或者AntDesignVue

这是全部的配置原文:

javascript 复制代码
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import electron from "vite-plugin-electron";
import electronRenderer from "vite-plugin-electron-renderer";
import polyfillExports from "vite-plugin-electron-renderer";
import { resolve } from "path";
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import ViteComponents, {
  AntDesignVueResolver
} from 'vite-plugin-components';

// 查找路径
const pathResolve = (dir: string): string => {
  return resolve(__dirname, ".", dir);
};
const alias: Record<string, string> = {
  "@": pathResolve("src"),
};

// https://vitejs.dev/config/
export default defineConfig((mode: any) => ({
  base: mode == "development" ? "" : "./",
  plugins: [
    vue(),
    electron([{
      entry: "electron-main/index.ts", //主进程
    }, {
      entry: "electron-preload/preload.ts"
    }]),
    electronRenderer(),
    polyfillExports(),
    // 按需引入AntDesignVue
    ViteComponents({customComponentResolvers: [AntDesignVueResolver()],}),
    // 按需引入elementUI
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }), Components({
      resolvers: [ElementPlusResolver()],
    })
  ],
  resolve: {
    alias,
  },
  build: {
    emptyOutDir: true, // outDir在root在根目录下,vite在构建的时候,会自动清空目录
    outDir: "dist-electron",
  }
}))

就暂时不描述,只可意会不可言传了。

相关推荐
sunfdf31 分钟前
Next.js 新手从零部署到首跑实战指南
开发语言·javascript·ecmascript
SmartBoyW40 分钟前
前端死磕:一文彻底搞懂 JS 事件循环 (Event Loop) 与宏微任务
前端·javascript
不法1 小时前
uniapp map地图导航/地图路线
前端·vue.js·uni-app
mONESY2 小时前
基于MCP协议搭建全链路智能Agent:地图检索+浏览器自动化+本地文件操控实战
javascript
研☆香2 小时前
闭包实战避坑指南
javascript
你怎么知道我是队长2 小时前
JavaScript 的控制语句介绍
开发语言·javascript·ecmascript
用户44014549314194 小时前
Spring Boot 3.x 异步编程实战:从 @Async 到虚拟线程
javascript
卓怡学长4 小时前
w263基于springboot + vue 健康饮食管理系统
java·数据库·vue.js·spring boot·spring·intellij-idea
无情的西瓜皮5 小时前
MCP 协议实战:从零搭建一个 MCP 服务器(Node.js 版)
vue.js·人工智能·typescript·node.js
wangruofeng5 小时前
终端里 rm 一下文件就没了,macOS 怎么删文件才进废纸篓
javascript·命令行·apple