vue.config.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const fs = require('fs');
  2. const path = require('path');
  3. let pages = {
  4. index: 'src/pages/index.js',
  5. mobile: 'src/pages/mobile.js',
  6. }
  7. module.exports = {
  8. pages: pages,
  9. assetsDir: process.env.VUE_APP_STATIC_DIR,
  10. publicPath: process.env.NODE_ENV === "production" ? "" : "",
  11. productionSourceMap: process.env.NODE_ENV !== "production",
  12. lintOnSave: false,
  13. devServer: {
  14. inline: false,
  15. hot: true,
  16. liveReload: false,
  17. },
  18. css: {
  19. loaderOptions: {
  20. less: {
  21. globalVars: getLessVariables(path.resolve(__dirname, './src/assets/style/globalVars.less'))
  22. }
  23. }
  24. }
  25. };
  26. function getLessVariables(file) {
  27. var themeContent = fs.readFileSync(file, 'utf-8')
  28. var variables = {}
  29. themeContent.split('\n').forEach(function(item) {
  30. if (item.indexOf('//') > -1 || item.indexOf('/*') > -1) {
  31. return
  32. }
  33. var _pair = item.split(':')
  34. if (_pair.length < 2) return;
  35. var key = _pair[0].replace('\r', '').replace('@', '')
  36. if (!key) return;
  37. var value = _pair[1].replace(';', '').replace('\r', '').replace(/^\s+|\s+$/g, '')
  38. variables[key] = value
  39. })
  40. return variables
  41. }