u
This commit is contained in:
1 parent
68e0785ec6
commit
57c0d98f11
189 files changed
+34329
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { URL, fileURLToPath } from "node:url";
|
||||
import process from "node:process";
|
||||
import { defineConfig, loadEnv } from "vite";
|
||||
import { setupVitePlugins } from "./build/plugins/index";
|
||||
import { getBuildTime } from "./build/config";
|
||||
|
||||
export default defineConfig((configEnv) => {
|
||||
const viteEnv = loadEnv(configEnv.mode, process.cwd()) as unknown as Env.ImportMeta;
|
||||
const { VITE_SERVER_BASEURL, VITE_APP_PROXY, VITE_APP_PROXY_PREFIX } = viteEnv;
|
||||
const buildTime = getBuildTime();
|
||||
return {
|
||||
base: viteEnv.VITE_BASE_URL,
|
||||
resolve: {
|
||||
// 使其通过能 ~ 或 @ 导入
|
||||
alias: {
|
||||
"~": fileURLToPath(new URL("./", import.meta.url)),
|
||||
"@": fileURLToPath(new URL("./src", import.meta.url))
|
||||
}
|
||||
},
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
api: "modern-compiler",
|
||||
additionalData: `@use "@/styles/scss/global.scss" as *;`
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: setupVitePlugins(viteEnv, buildTime),
|
||||
//
|
||||
define: {
|
||||
BUILD_TIME: JSON.stringify(buildTime)
|
||||
},
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
port: 8080,
|
||||
open: true,
|
||||
// 用于配置开发服务器启动时预加载的一些客户端文件,以提高初次加载的速度。
|
||||
warmup: {
|
||||
clientFiles: ["./index.html", "./src/{pages,components}/*"]
|
||||
},
|
||||
proxy:
|
||||
VITE_APP_PROXY === "Y"
|
||||
? {
|
||||
[VITE_APP_PROXY_PREFIX]: {
|
||||
target: VITE_SERVER_BASEURL,
|
||||
changeOrigin: true, // 跨域
|
||||
rewrite: (path) => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), "")
|
||||
}
|
||||
}
|
||||
: undefined
|
||||
},
|
||||
// 用于生产环境,可以使用vite preview预览构建后的应用 pnpm run preview
|
||||
preview: {
|
||||
port: 9725
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user