62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
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(({ command, mode }) => {
|
||
console.log("mode:", mode);
|
||
const env = loadEnv(mode, process.cwd(), "");
|
||
return {
|
||
plugins: [
|
||
uni(),
|
||
uniRouter({
|
||
includes: ["style"],
|
||
}),
|
||
weappTailwindcssDisabled ? undefined : vwt(),
|
||
],
|
||
css: {
|
||
postcss: {
|
||
plugins: postcssPlugin,
|
||
},
|
||
},
|
||
server: {
|
||
port: 8991,
|
||
},
|
||
base: mode != "dev" ? env.VITE_CDN_DIR : "./",
|
||
build: {
|
||
assetsDir: "static", // 静态资源存放目录(默认是 assets)
|
||
rollupOptions: {
|
||
output: {
|
||
// 代码分割配置
|
||
manualChunks: (id) => {
|
||
if (id.includes("node_modules")) {
|
||
return "vendor";
|
||
}
|
||
},
|
||
},
|
||
},
|
||
},
|
||
};
|
||
});
|