You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
// 引入 path 模块,用于处理路径
const path = require('path')
// 定义 resolve 函数, 用于快速拼接路径, __dirname 表示当前文件所在目录
function resolve(dir) {
return path.join(__dirname, dir)
}
// 定义 publicPath 函数,根据环境变量决定资源引用路径
function publicPath(){
if (process.env.NODE_ENV == 'production') {
// 生产环境使用相对路径 "././"
return "././";
} else {
// 开发环境使用绝对路径 "/"
return "/";
}
}
// vue.config.js 配置导出对象
module.exports = {
// 设置项目公共资源的基础路径,调用 publicPath() 动态判断
publicPath: publicPath(),
// 国际化配置:如果需要切换语言包,可以取消下面插件的注释,并调整路径
configureWebpack: {
// plugins: [
// new webpack.NormalModuleReplacementPlugin(
// /element-ui[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]zh-CN/,
// 'element-ui/lib/locale/lang/en'
// )
// ]
// 配置 Webpack 的解析规则
resolve: {
alias: {
// 设置别名 '@' 指向 src 目录,方便导入模块
'@': resolve('src')
}
}
},
// 开发服务器配置(仅在开发环境生效)
devServer: {
host: "0.0.0.0", // 指定开发服务器监听的 host, 默认是 localhost
port: 8081, // 指定开发服务器运行端口为 8081
hot: true, // 启用热更新功能(修改代码后无需刷新页面)
https: false, // 是否启用 HTTPS 模式(默认不启用)
// 配置请求代理,解决跨域问题
proxy: {
// 所有以 '/${schemaname}' 开头的请求都会被代理到目标服务器
'/${schemaname}': {
target: 'http://localhost:8080/${schemaname}/', // 要代理的目标服务器地址
changeOrigin: true, // 允许改变请求头中的 origin 字段为目标地址
secure: false, // 不验证 SSL 证书(适用于自签名 SSL 证书)
// 请求路径重写:将路径中开头的 '/${schemaname}' 替换为空字符串
pathRewrite: {
'^/${schemaname}': ''
}
}
}
}
}