import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import styleImport, { VantResolve } from "vite-plugin-style-import";
import { createHtmlPlugin } from "vite-plugin-html";
const getViteEnv = (mode: string, env: string) => {
return loadEnv(mode, process.cwd())[env];
};
export default ({ mode }) =>
defineConfig({
base: getViteEnv(mode, 'VITE_CONTEXT_PATH'),
plugins: [
vue(),
styleImport({
resolves: [VantResolve()],
libs: [
{
libraryName: "vant",
esModule: true,
resolveStyle: (name) => {
return `../es/${name}/style/index`;
},
},
],
}),
createHtmlPlugin({
inject: {
data: {
title: getViteEnv(mode, "VITE_APP_TITLE"),
},
},
}),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
assets: path.resolve(__dirname, "src/assets"),
},
},
});