Files
pqs-9100_client/frontend/vite.config.ts

111 lines
3.3 KiB
TypeScript
Raw Normal View History

2024-08-27 14:37:26 +08:00
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from "vite";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import vue from "@vitejs/plugin-vue";
import path from "path";
// 处理env环境参数读取
2024-08-27 14:37:26 +08:00
import { wrapperEnv } from "./build/getEnv";
import { createProxy } from "./build/proxy";
// 导入
import vueJsx from "@vitejs/plugin-vue-jsx";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { nodePolyfills } from 'vite-plugin-node-polyfills';
2024-08-22 11:27:06 +08:00
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
2024-08-27 14:37:26 +08:00
const root = process.cwd();
const env = loadEnv(mode, root);
const viteEnv = wrapperEnv(env);
2024-08-22 11:27:06 +08:00
return {
plugins: [
vue(),
2024-10-11 14:46:17 +08:00
vueJsx(),
2024-08-22 11:27:06 +08:00
// svg图标配置可以使用svg图标
createSvgIconsPlugin({
2024-08-27 14:37:26 +08:00
iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
symbolId: "icon-[dir]-[name]",
2024-08-22 11:27:06 +08:00
}),
AutoImport({
// 自动导入 Vue 相关函数ref, reactive, toRef 等
imports: ["vue", "@vueuse/core", "pinia", "vue-router", "vue-i18n"],
2024-08-27 14:37:26 +08:00
resolvers: [
// 自动导入 Element Plus 相关函数ElMessage, ElMessageBox... (带样式)
2024-08-27 14:37:26 +08:00
ElementPlusResolver({
importStyle: "sass",
}),
],
eslintrc: {
// 是否自动生成 eslint 规则,建议生成之后设置 false
enabled: false,
// 指定自动导入函数 eslint 规则的文件
filepath: "./.eslintrc-auto-import.json",
globalsPropValue: true,
},
// 是否在 vue 模板中自动导入
vueTemplate: true,
// 指定自动导入函数TS类型声明文件路径 (false:关闭自动生成)
dts: false,
// dts: "src/types/auto-imports.d.ts",
2024-08-22 11:27:06 +08:00
}),
Components({
2024-08-27 14:37:26 +08:00
resolvers: [
// 自动导入 Element Plus 组件
2024-08-27 14:37:26 +08:00
ElementPlusResolver({
importStyle: "sass",
}),
],
// 指定自定义组件位置(默认:src/components)
dirs: ["src/components", "src/**/components"],
// 指定自动导入组件TS类型声明文件路径 (false:关闭自动生成)
dts: false,
// dts: "src/types/components.d.ts",
2024-08-22 11:27:06 +08:00
}),
nodePolyfills({
include: ['crypto'],
globals: {
crypto: true,
},
}),
2024-08-22 11:27:06 +08:00
],
// 基础配置
base: viteEnv.VITE_PUBLIC_PATH,
root,
2024-08-27 14:37:26 +08:00
publicDir: "public",
2024-08-22 11:27:06 +08:00
resolve: {
alias: {
2024-08-27 14:37:26 +08:00
"@": path.resolve(__dirname, "src"),
"vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js",
2024-08-22 11:27:06 +08:00
},
},
css: {
preprocessorOptions: {
scss: {
prependData: `@import "@/styles/var.scss";`,
},
2024-08-22 11:27:06 +08:00
},
},
build: {
2024-08-27 14:37:26 +08:00
outDir: "dist",
assetsDir: "assets",
2024-08-22 11:27:06 +08:00
assetsInlineLimit: 4096,
cssCodeSplit: true,
sourcemap: false,
2024-08-27 14:37:26 +08:00
minify: "terser",
2024-08-22 11:27:06 +08:00
terserOptions: {
compress: {
// 生产环境去除console及debug
drop_console: false,
drop_debugger: true,
2024-08-07 21:48:57 +08:00
},
2024-08-22 11:27:06 +08:00
},
},
server: {
2024-08-27 14:37:26 +08:00
host: "0.0.0.0",
2024-08-22 11:27:06 +08:00
port: viteEnv.VITE_PORT,
open: viteEnv.VITE_OPEN,
cors: true,
proxy: createProxy(viteEnv.VITE_PROXY),
},
2024-08-27 14:37:26 +08:00
};
});