vue.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const { defineConfig } = require('@vue/cli-service')
  2. const time = new Date().getTime();
  3. module.exports = defineConfig({
  4. productionSourceMap: false,
  5. // 执行 npm run build 统一配置文件路径(本地访问dist/index.html需'./')
  6. // NODE_ENV:Node.js 暴露给执行脚本的系统环境变量。通常用于确定在开发环境还是生产环境
  7. publicPath: './',
  8. outputDir: 'dist', // 输出文件目录
  9. assetsDir: 'static', // 放置静态资源
  10. transpileDependencies: true,
  11. lintOnSave: false,
  12. // serve: {
  13. devServer: {
  14. port: 4000,
  15. open: true,
  16. proxy: {
  17. '/api': {
  18. target: process.env.VUE_APP_BASE_URL,
  19. changeOrigin: true,
  20. pathRewrite: {
  21. //路径重写
  22. '^/api': '/'
  23. }
  24. }
  25. }
  26. },
  27. configureWebpack: {
  28. output: { // 输出重构 打包编译后的 文件名称 【模块名称.版本号.时间戳】
  29. filename: `js/[name]-[hash].js?time=${time}`,
  30. chunkFilename: `js/[name]-[hash].js?time=${time}`,
  31. },
  32. }
  33. /*
  34. 接口请求 地址 需要以/api开头 才会反向代理到target源
  35. 路径重写: 定义/api 真实请求时这个路径携不携带
  36. 重要:真实请求地址是:target + 路径重写的值 + 请求path
  37. 假设路径重写被编程‘’ 则/api/a 真实请求地址是 url/a
  38. 注意:这里设置/api开头 则request.js中baseUrl应当设置为/api,否则反向代理并不成功
  39. */
  40. // }
  41. })