代码拉取完成,页面将自动刷新
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { visualizer } from "rollup-plugin-visualizer";
import { ConfigEnv, defineConfig, loadEnv, UserConfig } from "vite";
import viteCompression from "vite-plugin-compression";
import eslintPlugin from "vite-plugin-eslint";
import { createHtmlPlugin } from "vite-plugin-html";
import { createStyleImportPlugin } from "vite-plugin-style-import";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { wrapperEnv } from "./src/utils/getEnv";
// @see: https://vitejs.dev/config/
/** @type {import('vite').UserConfig} */
export default defineConfig((mode: ConfigEnv): UserConfig => {
const env = loadEnv(mode.mode, process.cwd());
const viteEnv = wrapperEnv(env);
return {
// base: "/",
// alias config
resolve: {
alias: {
"@": resolve(__dirname, "./src")
}
},
// global css
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
additionalData: `@import "@/styles/var.less";`
}
}
},
// server config
server: {
host: "127.0.0.1", // 服务器主机名,如果允许外部访问,可设置为"0.0.0.0"
port: viteEnv.VITE_PORT,
open: viteEnv.VITE_OPEN,
// cors: false,
// https: false,
// 代理跨域(mock 不需要配置,这里只是个示例)
proxy: {
"/admin": {
target: "http://127.0.0.1:8080/",
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, "")
},
"/api/admin": {
target: "http://127.0.0.1:8080/",
changeOrigin: true
}
}
},
plugins: [
react(),
createHtmlPlugin({
inject: {
data: {
title: viteEnv.VITE_GLOB_APP_TITLE
}
}
}),
// * 使用 svg 图标
createSvgIconsPlugin({
iconDirs: [resolve(process.cwd(), "src/assets/icons")],
symbolId: "icon-[dir]-[name]"
}),
createStyleImportPlugin({
libs: [
{
libraryName: "antd",
esModule: true,
resolveStyle: (name: any) => {
return `antd/es/${name}/style/index`;
}
}
]
}),
// * EsLint 报错信息显示在浏览器界面上
eslintPlugin(),
// * 是否生成包预览
viteEnv.VITE_REPORT && visualizer(),
// * gzip compress
viteEnv.VITE_BUILD_GZIP &&
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: "gzip",
ext: ".gz"
})
],
esbuild: {
pure: viteEnv.VITE_DROP_CONSOLE ? ["console.log", "debugger"] : []
},
base: "./",
// build configure
build: {
outDir: "dist",
// esbuild 打包更快,但是不能去除 console.log,去除 console 使用 terser 模式
minify: "esbuild",
// minify: "terser",
// terserOptions: {
// compress: {
// drop_console: viteEnv.VITE_DROP_CONSOLE,
// drop_debugger: true
// }
// },
rollupOptions: {
output: {
// Static resource classification and packaging
chunkFileNames: "assets/js/[name]-[hash].js",
entryFileNames: "assets/js/[name]-[hash].js",
assetFileNames: "assets/[name]-[hash].[ext]"
}
}
}
};
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。