vue.config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const autoprefixer = require("autoprefixer");
  2. const pxtorem = require("postcss-pxtorem");
  3. const path = require('path');
  4. const themePath = path.resolve(__dirname,'src/assets/style/theme.less');
  5. var os = require('os'), ip = '', ifaces = os.networkInterfaces() // 获取本机ip
  6. for (var i in ifaces) {
  7. for (var j in ifaces[i]) {
  8. var val = ifaces[i][j]
  9. if (val.family === 'IPv4' && val.address !== '127.0.0.1') {
  10. ip = val.address
  11. }
  12. }
  13. }
  14. module.exports = {
  15. // 关闭eslint检查
  16. lintOnSave: false,
  17. // 配置css前缀,px转rem
  18. css: {
  19. loaderOptions: {
  20. less: {
  21. modifyVars: {
  22. hack: `true; @import "${themePath}";`
  23. }
  24. },
  25. postcss: {
  26. plugins: [
  27. autoprefixer(),
  28. pxtorem({
  29. rootValue: 37.5,
  30. propList: ["*"]
  31. })
  32. ]
  33. }
  34. }
  35. },
  36. configureWebpack: {
  37. externals: {
  38. axios: "axios" // 配置使用CDN
  39. }
  40. },
  41. devServer: {
  42. open: true, //是否自动弹出浏览器页面
  43. port: '10087',
  44. https: false,
  45. hotOnly: false,
  46. // 代理
  47. proxy: {
  48. // 只要请求地址有'api'都会匹配上
  49. "/api": {
  50. target: "http://"+ip+":10010",
  51. ws: true,
  52. // 允许跨域
  53. changeOrigin: true,
  54. pathRewrite: {
  55. "^/api": "" //通过pathRewrite重写地址,将前缀/api转为/
  56. }
  57. }
  58. }
  59. }
  60. };