ant-design-vue

参考:
https://www.jianshu.com/p/58bc82a99f10
https://blog.csdn.net/weixin_43459866/article/details/112237617

在nuxt项目中如果使用了UI框架如antd vue、element等,主题定制配置是不可避免的问题。nuxt.config.js按照如下配置即可(以antd vue 为例)

  1. // 使用less-var-to-js将less的文件转换成为js文件,放入配置中.(lessToJs的配置文件只能放入公共的单个配置:例如@primary-color: #ddd;)
  2. import lessToJs from 'less-vars-to-js';
  3. // 设置全局的less
  4. const globalLess = fs.readFileSync('./assets/css/theme.less', 'utf8');
  5. const theme = lessToJs(globalLess)
  6. // Global CSS: https://go.nuxtjs.dev/config-css
  7. css: [
  8. 'ant-design-vue/dist/antd.less',
  9. 'swiper/css/swiper.css'
  10. ],
  11. // Modules: https://go.nuxtjs.dev/config-modules
  12. modules: [
  13. '@nuxtjs/axios',
  14. '@nuxtjs/style-resources'
  15. ],
  16. // Build Configuration: https://go.nuxtjs.dev/config-build
  17. build: {
  18. // 解决 启动 报Though the “loose“ option was set to “false“ in your @babel/preset-env config, it will not ...
  19. babel: {
  20. plugins: [
  21. ["@babel/plugin-proposal-private-methods", { "loose": true }]
  22. ]
  23. },
  24. loaders: {
  25. less: {
  26. modifyVars: theme,
  27. javascriptEnabled: true
  28. }
  29. },
  30. extend (config, ctx) {
  31. // todo svg
  32. const svgRule = config.module.rules.find(rule => rule.test.test('.svg'))
  33. svgRule.exclude = [path.resolve(__dirname, 'icons/svg')]
  34. // Includes /icons/svg for svg-sprite-loader
  35. config.module.rules.push({
  36. test: /\.svg$/,
  37. include: [path.resolve(__dirname, 'icons/svg')],
  38. loader: 'svg-sprite-loader',
  39. options: {
  40. symbolId: 'icon-[name]'
  41. }
  42. })
  43. }
  44. },

theme.less

  1. // ! 主题色
  2. @primary-color: #ff6a00;