vue.config.js 805 B

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