96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
import { fileURLToPath, URL } from "node:url";
|
|
import { defineConfig, loadEnv } from "vite";
|
|
import vue from "@vitejs/plugin-vue";
|
|
import vueJsx from "@vitejs/plugin-vue-jsx";
|
|
import AutoImport from "unplugin-auto-import/vite";
|
|
import Components from "unplugin-vue-components/vite";
|
|
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
|
|
import legacy from "@vitejs/plugin-legacy";
|
|
import { token } from "./src/styles/theme.json";
|
|
import {
|
|
setCrossoriginUseCredentials,
|
|
injectHtmlVars,
|
|
proxyConfig
|
|
} from "./vite.util";
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const envDir = `${process.cwd()}/env`;
|
|
const env = loadEnv(mode, envDir, "NODE_");
|
|
return {
|
|
base: "./",
|
|
envDir: "./env",
|
|
plugins: [
|
|
vue(),
|
|
vueJsx(),
|
|
AutoImport({
|
|
imports: ["vue", "pinia", {
|
|
"vue-router": [
|
|
"useLink",
|
|
"useRoute",
|
|
"useRouter",
|
|
"onBeforeRouteLeave",
|
|
"onBeforeRouteUpdate",
|
|
"createRouter",
|
|
"createWebHistory",
|
|
"createWebHashHistory"
|
|
]
|
|
}],
|
|
eslintrc: {
|
|
// 会在项目根目录自动生成.eslintrc-auto-import.json
|
|
enabled: true
|
|
}
|
|
}),
|
|
Components({
|
|
resolvers: [
|
|
AntDesignVueResolver({
|
|
importStyle: "less"
|
|
})
|
|
]
|
|
}),
|
|
legacy({
|
|
targets: ["chrome 52"],
|
|
additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
|
|
renderLegacyChunks: true,
|
|
polyfills: [
|
|
"es.symbol",
|
|
"es.array.filter",
|
|
"es.promise",
|
|
"es.promise.finally",
|
|
"es/map",
|
|
"es/set",
|
|
"es.array.for-each",
|
|
"es.object.define-properties",
|
|
"es.object.define-property",
|
|
"es.object.get-own-property-descriptor",
|
|
"es.object.get-own-property-descriptors",
|
|
"es.object.keys",
|
|
"es.object.to-string",
|
|
"web.dom-collections.for-each",
|
|
"esnext.global-this",
|
|
"esnext.string.match-all"
|
|
]
|
|
}),
|
|
setCrossoriginUseCredentials(),
|
|
injectHtmlVars(env)
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
"@": fileURLToPath(new URL("./src", import.meta.url))
|
|
}
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
less: {
|
|
modifyVars: token
|
|
}
|
|
}
|
|
},
|
|
server: {
|
|
proxy: proxyConfig(env)
|
|
},
|
|
build: {
|
|
modulePreload: false
|
|
}
|
|
};
|
|
});
|