vue.config.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const webpack = require('webpack')
  2. const fs = require('fs')
  3. const path = require('path')
  4. module.exports = {
  5. publicPath: "./",
  6. lintOnSave: false,
  7. productionSourceMap: false,
  8. css: {
  9. loaderOptions: {
  10. less: {
  11. // globalVars: getLessVariables(path.resolve(__dirname, './src/assets/style/globalVars.less'))
  12. }
  13. }
  14. },
  15. configureWebpack: {
  16. plugins: [
  17. new webpack.ProvidePlugin({
  18. globalMapState: ['vuex', 'mapState'],
  19. globalMapMutations: ['vuex', 'mapMutations'],
  20. globalMapGetters: ['vuex', 'mapGetters'],
  21. globalConfig: ['/src/config.js', 'default'],
  22. globalApi: ['/src/api.js', 'default'],
  23. globalUtils: ['/src/utils/index.js', 'default'],
  24. }),
  25. ],
  26. },
  27. devServer: {
  28. hot: true,
  29. liveReload: false,
  30. port: 8081,
  31. proxy: {
  32. '/YHT': {
  33. target: 'http://yuhuatai.4dage.com',
  34. changeOrigin: true,
  35. },
  36. '/YHTM': {
  37. target: 'http://yuhuatai.4dage.com',
  38. changeOrigin: true,
  39. }
  40. },
  41. }
  42. }
  43. function getLessVariables(file) {
  44. var themeContent = fs.readFileSync(file, 'utf-8')
  45. var variables = {}
  46. themeContent.split('\n').forEach(function(item) {
  47. if (item.indexOf('//') > -1 || item.indexOf('/*') > -1) {
  48. return
  49. }
  50. var _pair = item.split(':')
  51. if (_pair.length < 2) return
  52. var key = _pair[0].replace('\r', '').replace('@', '')
  53. if (!key) return
  54. var value = _pair[1].replace(';', '').replace('\r', '').replace(/^\s+|\s+$/g, '')
  55. variables[key] = value
  56. })
  57. return variables
  58. }