vue.config.js 830 B

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