3 Star 21 Fork 12

sohucw/admin-pro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
vite.config.ts 3.41 KB
一键复制 编辑 原始数据 按行查看 历史
dawei 提交于 2023-11-12 20:46 . feat: 搭建工程
import { defineConfig, loadEnv } from "vite";
import type { UserConfig, ConfigEnv } from "vite";
import { fileURLToPath } from "url";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
// 获取当前工作目录
const root = process.cwd();
// 获取环境变量
const env = loadEnv(mode, root);
console.log(env);
return {
// 项目根目录
root,
// 项目部署的基础路径
base: "./",
publicDir: fileURLToPath(new URL("./public", import.meta.url)), // 无需处理的静态资源位置
assetsInclude: fileURLToPath(new URL("./src/assets", import.meta.url)), // 需要处理的静态资源位置
plugins: [
// Vue模板文件编译插件
vue(),
// jsx文件编译插件
vueJsx(),
],
// 运行后本地预览的服务器
server: {
// 是否开启https
https: false,
// 指定服务器应该监听哪个 IP 地址。 如果将此设置为 0.0.0.0 或者 true 将监听所有地址,包括局域网和公网地址。
host: true,
// 开发环境预览服务器端口
port: 9000,
// 启动后是否自动打开浏览器
open: false,
// 是否开启CORS跨域
cors: true,
// 代理服务器
// 帮助我们开发时解决跨域问题
proxy: {
// 这里的意思是 以/api开头发送的请求都会被转发到 http://xxx:9000
[env.VITE_APP_API_BASEURL]: {
target: "http://localhost:9000",
// 改变 Host Header
changeOrigin: true,
// 发起请求时将 '/api' 替换为 ''
//rewrite: (path) => path.replace(/^\/api/, ""),
},
[env.VITE_APP_MOCK_BASEURL]: {
target: "http://localhost:9000",
// 改变 Host Header
changeOrigin: true,
// 发起请求时将 '/api' 替换为 ''
//rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
// 打包配置
build: {
// 关闭 sorcemap 报错不会映射到源码
sourcemap: false,
// 打包大小超出 400kb 提示警告
chunkSizeWarningLimit: 400,
rollupOptions: {
// 打包入口文件 根目录下的 index.html
// 也就是项目从哪个文件开始打包
input: {
index: fileURLToPath(
new URL("./index.html", import.meta.url),
),
},
// 静态资源分类打包
output: {
format: "esm",
chunkFileNames: "static/js/[name]-[hash].js",
entryFileNames: "static/js/[name]-[hash].js",
assetFileNames: "static/[ext]/[name]-[hash].[ext]",
},
},
},
// 配置别名
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
"#": fileURLToPath(new URL("./types", import.meta.url)),
},
},
};
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/sohucw/admin-pro.git
git@gitee.com:sohucw/admin-pro.git
sohucw
admin-pro
admin-pro
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385