build(环境变量): 📦 去除.env忽略、修改请求地址、控制台名称通过env获取

修改了环境变量的读取方式

调整了请求地址配置

控制台名称通过 .env 获取
This commit is contained in:
huangjunsen
2025-03-31 19:52:01 +08:00
parent fef8cece90
commit 20c1f0576b
7 changed files with 29 additions and 17 deletions
+1
View File
@@ -0,0 +1 @@
VUE_APP_TITLE=小智-智控台
+1
View File
@@ -0,0 +1 @@
VUE_APP_API_BASE_URL=https://2662r3426b.vicp.fun
+1
View File
@@ -0,0 +1 @@
VUE_APP_API_BASE_URL=https://2662r3426b.vicp.fun
+1 -1
View File
@@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>小智-智控台</title>
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
+2 -2
View File
@@ -7,7 +7,7 @@ import admin from './module/admin.js'
* 如果你想调用8002端口,就用'/xiaozhi-esp32-api/api/v1',请与vue.config.js的devServer配置相结合,方便跨域请求
*
*/
const DEV_API_SERVICE = 'https://2662r3426b.vicp.fun/xiaozhi-esp32-api'
// const DEV_API_SERVICE = 'https://2662r3426b.vicp.fun/xiaozhi-esp32-api'
// 8002开发完成完成后使用这个
// const DEV_API_SERVICE = '/xiaozhi-esp32-api'
@@ -16,7 +16,7 @@ const DEV_API_SERVICE = 'https://2662r3426b.vicp.fun/xiaozhi-esp32-api'
* @returns {string}
*/
export function getServiceUrl() {
return DEV_API_SERVICE
return '/xiaozhi-esp32-api'
}
+1
View File
@@ -5,6 +5,7 @@ import store from './store'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './styles/global.scss'
Vue.use(ElementUI);
Vue.config.productionTip = false
+22 -14
View File
@@ -3,22 +3,30 @@ const dotenv = require('dotenv');
// 确保加载 .env 文件
dotenv.config();
console.log("base_url",process.env.VUE_APP_API_BASE_URL);
module.exports = defineConfig({
devServer: {
// Bug 修复:将代理配置为环境变量中定义的 API 基础 URL
port: 8001, // 指定端口为 8001
proxy: {
'/xiaozhi-esp32-api': {
target: process.env.VUE_APP_API_BASE_URL || 'http://localhost:8002', // 后端 API 的基础 URL
changeOrigin: true, // 允许跨域
// pathRewrite: {
// '^/api': '', // 路径重写
// },
},
},
client: {
overlay: false,
chainWebpack: config => {
config.plugin('html')
.tap(args => {
// 将 VUE_APP_TITLE 从环境变量中注入到 HTML 中
args[0].title = process.env.VUE_APP_TITLE || '小智-智控台';
return args;
});
},
devServer: {
port: 8001, // 指定端口为 8001
proxy: {
'/xiaozhi-esp32-api': {
target: process.env.VUE_APP_API_BASE_URL, // 后端 API 的基础 URL
changeOrigin: true, // 允许跨域
pathRewrite: {
'^/api': '', // 路径重写
},
},
},
client: {
overlay: false, // 不显示 webpack 错误覆盖层
},
},
});