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

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

你可能感兴趣的:(electron,javascript,vue.js)