const { defineConfig } = require('@vue/cli-service') const path = require('path') const resolve = dir => { return path.join(__dirname, dir) } module.exports = defineConfig({ publicPath: './', transpileDependencies: [], chainWebpack: config => { config.resolve.alias .set('_c', resolve('src/components')) }, // 修正 devServer 配置 devServer: { port: 81, host: 'localhost', open: true, // 添加禁用主机检查,避免 Invalid Host header 错误 allowedHosts: 'all', // 添加更严格的代理配置 proxy: { '/dev-api': { target: 'http://localhost:8080', // 后端在8080端口 changeOrigin: true, secure: false, // 如果后端是http,需要这个 logLevel: 'debug', // 可以查看代理日志 pathRewrite: { '^/dev-api': '' // 移除 /dev-api 前缀,直接转发到后端根路径 }, // 添加headers确保正确传递 headers: { Connection: 'keep-alive' } } } }, outputDir: 'dist', assetsDir: 'static' })