import { defineConfig } from "vite";
import postcssPxToViewport from "postcss-px-to-viewport";
import path from "path";
import vue from "@vitejs/plugin-vue";
import { viteMockServe } from "vite-plugin-mock";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
export default defineConfig({
esbuild: {
pure: ["console.log"],
drop: ["debugger"],
},
mode: import.meta.env.MODE === "development" ? "development" : "production",
plugins: [
vue(),
viteMockServe(),
AutoImport({
imports: ["vue"],
dts: "src/auto-import.d.ts",
}),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
optimizeDeps: {
force: true,
},
resolve: {
extensions: [".js", ".ts", ".json"],
alias: [
{
find: "@",
replacement: resolve(__dirname, "src"),
},
{
find: "components",
replacement: resolve(__dirname, "src/components"),
},
],
},
server: {
proxy: {
"/api": {
target: "http url",
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/api/, ""),
},
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@import '/src/assets/styles/variables.scss';`,
},
},
postcss: {
plugins: [
postcssPxToViewport({
viewportWidth: 375,
}),
],
},
},
build: {
minify: "terser",
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
outDir: "dist",
assetsDir: "static",
assetsInlineLimit: 4096,
reportCompressedSize: false,
chunkSizeWarningLimit: 1024,
commonjsOptions: {
ignoreTryCatch: false,
},
sourcemap: false,
rollupOptions: {
output: {
chunkFileNames: "js/[name]-[hash].js",
entryFileNames: "js/[name]-[hash].js",
assetFileNames: "[ext]/[name]-[hash].[ext]",
manualChunks(id) {
if (id.includes("node_modules")) {
return id
.toString()
.split("node_modules/")[1]
.split("/")[0]
.toString();
}
},
},
},
},
});