vue.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. const { defineConfig } = require('@vue/cli-service')
  2. module.exports = defineConfig({
  3. transpileDependencies: true,
  4. // 配置开发服务器(包括代理)
  5. publicPath: "/",
  6. // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
  7. outputDir: 'dist',
  8. // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  9. assetsDir: 'static',
  10. // 是否开启eslint保存检测,有效值:ture | false | 'error'
  11. lintOnSave: true, // 保存时触发ESLint检查,有错误仅警告,不阻断编译
  12. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  13. productionSourceMap: false,
  14. devServer: {
  15. // 开启代理
  16. proxy: {
  17. // 1. 匹配以 /api 开头的请求(自定义前缀)
  18. '/api': {
  19. // 目标后端接口地址(替换成你的实际接口地址)
  20. target: 'http://47.108.204.221:6104/',
  21. // 开启跨域(必须设置,否则代理无效)
  22. changeOrigin: true,
  23. // 路径重写:去掉请求路径中的 /api 前缀(根据后端接口是否需要前缀决定)
  24. // 例如:前端请求 /api/user → 实际转发到 http://localhost:8080/user
  25. pathRewrite: {
  26. '^/api': ''
  27. },
  28. // 可选:如果后端是 https 接口,需要设置为 true
  29. // secure: false
  30. },
  31. }
  32. }
  33. })