vue.config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. }
  28. function getLessVariables(file) {
  29. var themeContent = fs.readFileSync(file, 'utf-8')
  30. var variables = {}
  31. themeContent.split('\n').forEach(function(item) {
  32. if (item.indexOf('//') > -1 || item.indexOf('/*') > -1) {
  33. return
  34. }
  35. var _pair = item.split(':')
  36. if (_pair.length < 2) return
  37. var key = _pair[0].replace('\r', '').replace('@', '')
  38. if (!key) return
  39. var value = _pair[1].replace(';', '').replace('\r', '').replace(/^\s+|\s+$/g, '')
  40. variables[key] = value
  41. })
  42. return variables
  43. }