Files
gen-form/vite.config.js

59 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2022-12-14 16:57:57 +08:00
import { defineConfig, loadEnv } from "vite";
import path from "path";
import createVitePlugins from "./vite/plugins";
// import vueJsx from "@vitejs/plugin-vue-jsx";
2021-11-30 09:55:37 +08:00
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
2022-12-14 16:57:57 +08:00
const env = loadEnv(mode, process.cwd());
const { VITE_APP_ENV } = env;
2021-11-30 09:55:37 +08:00
return {
2022-03-02 17:15:45 +08:00
// 部署生产环境和开发环境下的URL。
// 默认情况下vite 会假设你的应用是被部署在一个域名的根路径上
// 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
2022-12-14 16:57:57 +08:00
base: VITE_APP_ENV === "production" ? "/" : "/",
plugins: createVitePlugins(env, command === "build"),
2021-11-30 09:55:37 +08:00
resolve: {
// https://cn.vitejs.dev/config/#resolve-alias
alias: {
// 设置路径
2022-12-14 16:57:57 +08:00
"~": path.resolve(__dirname, "./"),
2021-11-30 09:55:37 +08:00
// 设置别名
2022-12-14 16:57:57 +08:00
"@": path.resolve(__dirname, "./src"),
2021-11-30 09:55:37 +08:00
},
// https://cn.vitejs.dev/config/#resolve-extensions
2022-12-14 16:57:57 +08:00
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
2021-11-30 09:55:37 +08:00
},
2022-03-18 15:01:07 +08:00
// vite 相关配置
2021-11-30 09:55:37 +08:00
server: {
port: 80,
2021-12-30 09:54:06 +08:00
host: true,
2021-11-30 09:55:37 +08:00
open: true,
proxy: {
// https://cn.vitejs.dev/config/#server-proxy
2022-12-14 16:57:57 +08:00
"/dev-api": {
target: "http://vue.ruoyi.vip/prod-api",
2021-11-30 09:55:37 +08:00
changeOrigin: true,
2022-12-14 16:57:57 +08:00
rewrite: (p) => p.replace(/^\/dev-api/, ""),
},
},
2021-11-30 09:55:37 +08:00
},
2022-03-18 15:01:07 +08:00
//fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
css: {
postcss: {
plugins: [
{
2022-12-14 16:57:57 +08:00
postcssPlugin: "internal:charset-removal",
AtRule: {
charset: (atRule) => {
2022-12-14 16:57:57 +08:00
if (atRule.name === "charset") {
atRule.remove();
}
2022-12-14 16:57:57 +08:00
},
},
},
],
},
},
};
});