vue.config.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const fs = require('fs');
  2. const path = require('path');
  3. module.exports = {
  4. publicPath: "./",
  5. css: {
  6. loaderOptions: {
  7. less: {
  8. globalVars: getLessVariables(path.resolve(__dirname, './src/assets/css/globalVars.less'))
  9. }
  10. }
  11. },
  12. devServer: {
  13. proxy: {
  14. '/data': {
  15. target: 'http://192.168.0.135:8001',
  16. changeOrigin: true,
  17. // pathRewrite: {
  18. // '^/api': '/api'
  19. // }
  20. }
  21. }
  22. },
  23. configureWebpack: {
  24. resolve: {
  25. alias: {
  26. '@': path.resolve(__dirname, 'src')
  27. }
  28. }
  29. },
  30. };
  31. function getLessVariables(file) {
  32. var themeContent = fs.readFileSync(file, 'utf-8')
  33. var variables = {}
  34. themeContent.split('\n').forEach(function (item) {
  35. if (item.indexOf('//') > -1 || item.indexOf('/*') > -1) {
  36. return
  37. }
  38. var _pair = item.split(':')
  39. if (_pair.length < 2) return;
  40. var key = _pair[0].replace('\r', '').replace('@', '')
  41. if (!key) return;
  42. var value = _pair[1].replace(';', '').replace('\r', '').replace(/^\s+|\s+$/g, '')
  43. variables[key] = value
  44. })
  45. return variables
  46. }