vue.config.js 860 B

1234567891011121314151617181920212223242526272829303132333435
  1. const fs = require('fs');
  2. const path = require('path');
  3. module.exports = {
  4. publicPath: "./",
  5. lintOnSave: false,
  6. productionSourceMap: false,
  7. css: {
  8. loaderOptions: {
  9. less: {
  10. globalVars: getLessVariables(path.resolve(__dirname, './src/assets/style/globalVars.less'))
  11. }
  12. }
  13. }
  14. };
  15. function getLessVariables(file) {
  16. var themeContent = fs.readFileSync(file, 'utf-8')
  17. var variables = {}
  18. themeContent.split('\n').forEach(function(item) {
  19. if (item.indexOf('//') > -1 || item.indexOf('/*') > -1) {
  20. return
  21. }
  22. var _pair = item.split(':')
  23. if (_pair.length < 2) return;
  24. var key = _pair[0].replace('\r', '').replace('@', '')
  25. if (!key) return;
  26. var value = _pair[1].replace(';', '').replace('\r', '').replace(/^\s+|\s+$/g, '')
  27. variables[key] = value
  28. })
  29. return variables
  30. }