ai-agent-m/vite.config.ts
2025-03-20 09:22:17 +08:00

57 lines
1.6 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 { defineConfig, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import tailwindcss from "tailwindcss";
import autoprefixer from "autoprefixer";
import postcssRemToResponsivePixel from "postcss-rem-to-responsive-pixel";
import postcssWeappTailwindcssRename from "weapp-tailwindcss-webpack-plugin/postcss";
import vwt from "weapp-tailwindcss-webpack-plugin/vite";
import uniRouter from "unplugin-uni-router/vite";
const isH5 = process.env.UNI_PLATFORM === "h5";
const isApp = process.env.UNI_PLATFORM === "app";
const weappTailwindcssDisabled = isH5 || isApp;
const postcssPlugin = [autoprefixer(), tailwindcss()];
if (!weappTailwindcssDisabled) {
postcssPlugin.push(
postcssRemToResponsivePixel({
rootValue: 32,
propList: ["*"],
transformUnit: "rpx",
})
);
postcssPlugin.push(postcssWeappTailwindcssRename());
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// 加载环境变量
const env = loadEnv(mode, process.cwd());
console.log("env", env.VITE_MODE);
return {
// base: "https://cdn.xglpa.com/ai-agent-m/",
plugins: [
uni(),
uniRouter({
includes: ["style"],
}),
weappTailwindcssDisabled ? undefined : vwt(),
],
css: {
postcss: {
plugins: postcssPlugin,
},
},
server: {
port: 8991,
},
// 根据环境变量动态配置
build: {
outDir: `dist/${mode}`, // 输出到不同目录(如 dist/development、dist/test
assetsDir: "static",
minify: mode === "production" ? "terser" : false, // 生产环境压缩代码
},
};
});