Files
peko-admin-web/vue.config.js

67 lines
2.2 KiB
JavaScript
Raw Normal View History

2025-04-03 10:53:18 +08:00
// 引入 Vue CLI 的 defineConfig 方法
2023-09-18 11:34:27 +08:00
const { defineConfig } = require('@vue/cli-service')
2025-04-03 10:53:18 +08:00
// 引入 webpack
2023-09-18 11:34:27 +08:00
var webpack = require('webpack')
2025-04-03 10:53:18 +08:00
// 引入 unplugin-auto-import 插件的 webpack 版本
2023-10-30 17:07:00 +08:00
var AutoImport = require('unplugin-auto-import/webpack')
2025-04-03 10:53:18 +08:00
// 引入 unplugin-vue-components 插件的 webpack 版本
2023-10-30 16:10:33 +08:00
var Components = require('unplugin-vue-components/webpack')
2025-04-03 10:53:18 +08:00
// 引入 Element Plus 的解析器
2023-10-30 16:10:33 +08:00
var { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
2025-04-03 10:53:18 +08:00
2023-09-18 11:34:27 +08:00
module.exports = defineConfig({
2025-04-03 10:53:18 +08:00
// 禁用多线程
parallel: false,
// 配置需要转译的依赖
2023-10-30 17:07:00 +08:00
transpileDependencies: true,
2025-04-03 10:53:18 +08:00
// 使用 chainWebpack 自定义 webpack 配置
2023-10-30 17:07:00 +08:00
chainWebpack: config => {
config
2025-04-03 10:53:18 +08:00
.plugin('html') // 配置 html-webpack-plugin 插件
2023-10-30 17:07:00 +08:00
.tap(args => {
2025-04-03 10:53:18 +08:00
args[0].title = 'MOLISTAR管理后台' // 设置网页标题
2023-10-30 17:07:00 +08:00
return args
})
},
2025-04-03 10:53:18 +08:00
// 配置 webpack 插件
2023-10-30 17:07:00 +08:00
configureWebpack: {
plugins: [
2025-04-03 10:53:18 +08:00
// 配置 ProvidePlugin自动加载模块
2023-10-30 17:07:00 +08:00
new webpack.ProvidePlugin({
2025-04-03 10:53:18 +08:00
$: 'jquery', // 自动加载 jquery
2023-10-30 17:07:00 +08:00
jQuery: 'jquery',
'windows.jQuery': 'jquery',
2025-04-03 10:53:18 +08:00
Popper: ['popper.js', 'default'] // 自动加载 popper.js
2023-10-30 17:07:00 +08:00
}),
2025-04-03 10:53:18 +08:00
// 配置 unplugin-auto-import 插件,自动导入 API
2023-10-30 17:07:00 +08:00
AutoImport({
2025-04-03 10:53:18 +08:00
resolvers: [ElementPlusResolver()], // 使用 Element Plus 解析器
2023-10-30 17:07:00 +08:00
}),
2025-04-03 10:53:18 +08:00
// 配置 unplugin-vue-components 插件,自动注册组件
2023-10-30 17:07:00 +08:00
Components({
2025-04-03 10:53:18 +08:00
resolvers: [ElementPlusResolver()], // 使用 Element Plus 解析器
2023-10-30 17:07:00 +08:00
}),
],
},
2025-04-03 10:53:18 +08:00
// 配置开发服务器
2023-10-30 17:07:00 +08:00
devServer: {
2025-04-03 10:53:18 +08:00
port: 8081, // 设置开发服务器端口
2023-10-30 17:07:00 +08:00
headers: {
2025-04-03 10:53:18 +08:00
'Access-Control-Allow-Origin': '*', // 允许跨域请求
2023-09-18 11:34:27 +08:00
},
2023-10-30 17:07:00 +08:00
proxy: {
'/': {
2025-04-03 10:53:18 +08:00
ws: false, // 禁用 WebSocket
target: process.env.VUE_APP_API_BASE_URL, // 设置代理目标地址
changeOrigin: true, // 修改请求的源
2023-10-30 17:07:00 +08:00
pathRewrite: {
2025-04-03 10:53:18 +08:00
'^/': '' // 重写路径,去掉根路径
2023-10-30 17:07:00 +08:00
}
}
2023-09-18 11:34:27 +08:00
},
2023-12-04 14:20:20 +08:00
client: {
2025-04-03 10:53:18 +08:00
// 当出现编译错误或警告时,是否在浏览器中显示全屏覆盖
overlay: false // 示例为只显示错误信息
},
2023-10-30 17:07:00 +08:00
},
2025-04-03 10:53:18 +08:00
})