vue.config.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const webpack = require('webpack')
  2. const fs = require('fs')
  3. const path = require('path')
  4. const dayjs = require('dayjs')
  5. const time = dayjs().format('YYYY-M-D HH:mm:ss')
  6. process.env.VUE_APP_UPDATE_TIME = time
  7. module.exports = {
  8. publicPath: process.env.PUBLIC_PATH,
  9. lintOnSave: false,
  10. productionSourceMap: false,
  11. css: {
  12. loaderOptions: {
  13. less: {
  14. // globalVars: getLessVariables(path.resolve(__dirname, './src/assets/style/globalVars.less'))
  15. }
  16. }
  17. },
  18. configureWebpack: {
  19. plugins: [
  20. new webpack.ProvidePlugin({
  21. globalMapState: ['vuex', 'mapState'],
  22. globalMapMutations: ['vuex', 'mapMutations'],
  23. globalMapGetters: ['vuex', 'mapGetters'],
  24. globalConfig: ['/src/config.js', 'default'],
  25. globalApi: ['/src/api.js', 'default'],
  26. globalUtils: ['/src/utils/index.js', 'default'],
  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. }