微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vite配置electron、ElementPlus或者AntDesignVue

这是全部的配置原文:

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",
  }
}))

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐