代码拉取完成,页面将自动刷新
import { fileURLToPath, URL } from "node:url";
import {defineConfig, loadEnv} from 'vite'
import react from '@vitejs/plugin-react'
import vitePluginImp from "vite-plugin-imp";
import { viteMockServe } from "vite-plugin-mock";
import { resolve } from "path";
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) =>{
const env = loadEnv(mode, __dirname);
console.log("env", env);
return {
base: env.VITE_MODE == "production" ? "/react-vite/" : "/",
plugins: [
react(),
// 配置mock
viteMockServe({
mockPath: "/mock",
localEnabled: true
}),
vitePluginImp({
libList: [
{
libName: "antd",
style: (name) => `antd/es/${name}/style`,
},
],
}),
],
css: {
//* css模块化
modules: {
// css模块化 文件以.module.[css|less|scss]结尾
generateScopedName: "[name]__[local]___[hash:base64:5]",
hashPrefix: "prefix",
},
//* 预编译支持less 并且设置主题颜色
preprocessorOptions: {
less: {
javascriptEnabled: true,
modifyVars: {
"primary-color": "#0fcb09", //设置antd主题色
"font-size-base": "20px", // 主字号
"@border-radius-base": "10px",
},
},
},
},
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
"#": resolve(__dirname, '/src/types'),
},
extensions: [".js", ".ts", "tsx"], // 使用路径别名时想要省略的后缀名,可以自己 增减
},
build: {
outDir: "react-vite",
// 兼容 Chrome 内核比较低的浏览器,如 360、QQ 浏览器
target: "chrome63",
cssTarget: "chrome63",
terserOptions: {
compress: {
keep_infinity: true,
// Used to delete console in production environment
drop_console: true,
},
},
// Turning off brotliSize display can slightly reduce packaging time
reportCompressedSize: false,
chunkSizeWarningLimit: 2000,
},
optimizeDeps: {
include: [
"antd/es/locale/zh_CN",
"antd/es/locale/en_US"
],
exclude: ["vue-demi", "consolidate"],
}
}
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。