vue.config.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const version = new Date().getTime();
  2. module.exports = {
  3. outputDir: 'sc',
  4. publicPath: "/sc",
  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. '/': { //前端任何含/api的URL请求都会被反向代理。如http://localhost:8000/xxx/api/source/xxx的请求会变成服务器的反向代理请求
  34. target: 'http://120.25.151.99:49011', //原来请求的服务器IP地址会换成此地址,如以上地址会变成http://localhost:5000/xxx/api/source/xxx
  35. // target: 'http://112.74.63.148:49011', //原来请求的服务器IP地址会换成此地址,如以上地址会变成http://localhost:5000/xxx/api/source/xxx
  36. changeOrigin: true, // 是否跨域
  37. pathRewrite: {
  38. // '.+?/api': '/api'
  39. } // 这里会对反向代理的地址进行重写。比如我的实际后端资源的URI是http://localhost:5000/api/resource,那么不加这个配置属性的话是访问不到我这个有效地址的。这里配置是一个正则替换,替换后就是后端api真正有效的地址了
  40. },
  41. "/weixin": {
  42. target: "https://api.weixin.qq.com/",
  43. ws: true,
  44. secure: true, // 使用的是http协议设置为 false,https协议设置为 true
  45. changeOrigin: true,
  46. pathRewrite: {
  47. "^/weixin": "",
  48. }
  49. }
  50. },
  51. disableHostCheck: true,
  52. }
  53. }