vue.config.js 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.44:8110',
  16. changeOrigin: true,
  17. // pathRewrite: {
  18. // '^/api': '/api'
  19. // }
  20. }
  21. }
  22. }
  23. };
  24. function getLessVariables(file) {
  25. var themeContent = fs.readFileSync(file, 'utf-8')
  26. var variables = {}
  27. themeContent.split('\n').forEach(function (item) {
  28. if (item.indexOf('//') > -1 || item.indexOf('/*') > -1) {
  29. return
  30. }
  31. var _pair = item.split(':')
  32. if (_pair.length < 2) return;
  33. var key = _pair[0].replace('\r', '').replace('@', '')
  34. if (!key) return;
  35. var value = _pair[1].replace(';', '').replace('\r', '').replace(/^\s+|\s+$/g, '')
  36. variables[key] = value
  37. })
  38. return variables
  39. }