vue.config.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const version = new Date().getTime();
  2. module.exports = {
  3. outputDir: "shenze",
  4. publicPath: "/shenze",
  5. assetsDir: "static",
  6. css: {
  7. // extract: false
  8. extract:
  9. process.env.NODE_ENV === "production"
  10. ? {
  11. filename: `css/[name].${version}.css`,
  12. chunkFilename: `css/[name].${version}.css`,
  13. }
  14. : false,
  15. },
  16. filenameHashing: true,
  17. configureWebpack: {
  18. output: {
  19. // 动态文件名配置
  20. filename:
  21. process.env.NODE_ENV === "production"
  22. ? `js/[name].[contenthash:8].${version}.js`
  23. : "js/[name].js",
  24. chunkFilename:
  25. process.env.NODE_ENV === "production"
  26. ? `js/[name].[contenthash:8].${version}.js`
  27. : "js/[name].js",
  28. },
  29. },
  30. devServer: {
  31. open: true,
  32. proxy: {
  33. "/": {
  34. //前端任何含/api的URL请求都会被反向代理。如http://localhost:8000/xxx/api/source/xxx的请求会变成服务器的反向代理请求
  35. target: "http://120.25.151.99:49011", //原来请求的服务器IP地址会换成此地址,如以上地址会变成http://localhost:5000/xxx/api/source/xxx
  36. // target: 'http://112.74.63.148:49011', //原来请求的服务器IP地址会换成此地址,如以上地址会变成http://localhost:5000/xxx/api/source/xxx
  37. changeOrigin: true, // 是否跨域
  38. pathRewrite: {
  39. // '.+?/api': '/api'
  40. }, // 这里会对反向代理的地址进行重写。比如我的实际后端资源的URI是http://localhost:5000/api/resource,那么不加这个配置属性的话是访问不到我这个有效地址的。这里配置是一个正则替换,替换后就是后端api真正有效的地址了
  41. },
  42. "/weixin": {
  43. target: "https://api.weixin.qq.com/",
  44. ws: true,
  45. secure: true, // 使用的是http协议设置为 false,https协议设置为 true
  46. changeOrigin: true,
  47. pathRewrite: {
  48. "^/weixin": "",
  49. },
  50. },
  51. },
  52. disableHostCheck: true,
  53. },
  54. };