hi-sass-frame/.electron-vite/vite.config.mts

178 lines
5.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {join} from "path";
import {UserConfig, ConfigEnv, loadEnv, defineConfig} from "vite";
import vuePlugin from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import viteIkarosTools from "./plugin/vite-ikaros-tools";
import {getConfig} from "./utils";
import dayjs from "dayjs";
/**
* 自动引用功能
*/
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import {ElementPlusResolver} from "unplugin-vue-components/resolvers";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";
/**
* SVG图标
*/
import {createSvgIconsPlugin} from "vite-plugin-svg-icons";
/**
* univerJs插件
*/
import {univerPlugin} from "@univerjs/vite-plugin";
import UnoCSS from "unocss/vite";
/**
* 需要预加载的资源
*/
import {preloads} from "./preloads";
function resolve(dir: string) {
return join(__dirname, "..", dir);
}
const config = getConfig();
import pkg from "../package.json";
/** 平台的名称、版本、运行所需的`node`版本、依赖、构建时间的类型提示 */
const __APP_INFO__ = {
pkg: pkg,
buildTimestamp: Date.now(),
lastBuildTime: dayjs().format("YYYY-MM-DD HH:mm:ss")
};
const root = resolve("src/renderer");
const src = resolve("src");
// const theme: string = resolve("src/renderer/themes/default");
const theme: string = resolve("src/renderer/themes/geeker");
const themeGeeker: string = resolve("src/renderer/themes/geeker");
const themeDefault: string = resolve("src/renderer/themes/default");
const mode = config && config.NODE_ENV;
export default defineConfig({
mode: mode,
root: root,
define: {
__CONFIG__: config,
__ISWEB__: Number(config && config.target),
__APP_INFO__: JSON.stringify(__APP_INFO__),
'process.env': process.env,
},
resolve: {
alias: {
"@": root,
"@api": join(root, "/api"),
"@config": join(src, "../config"),
"@main": join(src, "/main"),
"@mock": join(root, "/mock"),
"@renderer": root,
"@src": src,
"@store": join(root, "/store/modules"),
"@theme": theme,
"@themeDefault": themeDefault,
"@themeGeeker": themeGeeker,
},
},
base: "./",
build: {
outDir:
config && config.target
? resolve("dist/web")
: resolve("dist/electron/renderer"),
emptyOutDir: true,
target: "esnext",
cssCodeSplit: false,
},
css: {
// CSS 预处理器
preprocessorOptions: {
// 定义全局 SCSS 变量
scss: {
javascriptEnabled: true,
additionalData: `
@use "@themeDefault/styles/variables.scss" as *;
// @use "@themeGeeker/styles/var.scss" as *;
`,
},
},
},
server: {
// 无须配置
},
plugins: [
vuePlugin(),
// jsx、tsx语法支持
vueJsx(),
viteIkarosTools(),
//CSS预处理
UnoCSS({
hmrTopLevelAwait: false,
}),
// univerjs的虚拟化插件技术用于语言包的自动引用
univerPlugin(),
// 自动导入参考: https://github.com/sxzz/element-plus-best-practices/blob/main/vite.config.ts
AutoImport({
// 自动导入 Vue 相关函数ref, reactive, toRef 等
imports: ["vue", "@vueuse/core", "pinia", "vue-router", "vue-i18n"],
resolvers: [
// 自动导入 Element Plus 相关函数ElMessage, ElMessageBox... (带样式)
ElementPlusResolver(),
// 自动导入图标组件
IconsResolver({}),
],
// 是否在 vue 模板中自动导入
vueTemplate: true,
// 指定自动导入函数TS类型声明文件路径 (false:关闭自动生成)
// dts: false,
dts: "fixTypes/auto-imports.d.ts",
}),
Components({
resolvers: [
// 自动导入 Element Plus 组件
ElementPlusResolver(),
/**
* 自动注册图标组件
*/
IconsResolver({
// element-plus图标库其他图标库 https://icon-sets.iconify.design/
enabledCollections: ["ep"],
}),
],
/**
* 指定自定义组件位置(默认:src/components)
* TBD resolve("@theme/components"),测试用法,效果未知
*/
// dirs: ["src/components", join(theme, "/components"), join(theme, "/**/components")],
dirs: ["src/components", join(themeDefault, "/components"), join(themeDefault, "/**/components"),"src/**/components"],
// 指定自动导入组件TS类型声明文件路径 (false:关闭自动生成)
// dts: false,
dts: "fixTypes/components.d.ts",
}),
Icons({
// 自动安装图标库
autoInstall: true,
}),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [join(themeDefault, "assets/icons"),join(themeGeeker, "assets/icons"),"@renderer/assets/icons"],
// 指定symbolId格式
symbolId: "icon-[dir]-[name]",
}),
// node({
// // 默认情况下,`node` 插件会重写 `process` 和全局变量。
// // 如果你不想要这个行为,可以将 `mock` 设置为 `false`。
// mock: true,
//
// // 如果你想要包括一些特定的Node.js全局变量可以在 `additional` 中指定。
// additional: ['process', 'fs', 'path']
// })
],
optimizeDeps: preloads,
});