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";
|
|
|
|
|
|
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";
|
2024-08-08 19:08:15 +08:00
|
|
|
|
|
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(),
|
|
|
|
|
|
// 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({
|
2024-08-27 14:37:26 +08:00
|
|
|
|
resolvers: [
|
|
|
|
|
|
ElementPlusResolver({
|
|
|
|
|
|
importStyle: "sass",
|
|
|
|
|
|
}),
|
|
|
|
|
|
],
|
2024-08-22 11:27:06 +08:00
|
|
|
|
}),
|
|
|
|
|
|
Components({
|
2024-08-27 14:37:26 +08:00
|
|
|
|
resolvers: [
|
|
|
|
|
|
ElementPlusResolver({
|
|
|
|
|
|
importStyle: "sass",
|
|
|
|
|
|
}),
|
|
|
|
|
|
],
|
2024-08-22 11:27:06 +08:00
|
|
|
|
}),
|
2024-08-27 14:37:26 +08:00
|
|
|
|
// 增加此行代码
|
|
|
|
|
|
vueJsx(),
|
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-08 19:08:15 +08:00
|
|
|
|
},
|
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
|
|
|
|
};
|
|
|
|
|
|
});
|