vite+element-plus `buildModifiers`报错


参考文档:https://element-plus.gitee.io/#/zh-CN/component/quickstart

最近尝试用vue3+vite+element-plus写一个小demo,安装完后,粘贴element-plus代码发现了如下报错:

后又重新看了一遍element-plus文档,发现上面有vite的配置方法,而我遗漏了


跟着文档上操作:

  1. 安装vite-plugin-style-import

根据文档描述,还需要在vite.config.js中配置

  1. 在vite.config.js中
import styleImport from 'vite-plugin-style-import'

export default defineConfig({
  plugins: [
    vue(),
    // 此为使用scss的配置
    styleImport({
      libs: [{
        libraryName: 'element-plus',
        esModule: true,
        ensureStyleFile: true,
        resolveStyle: (name) => {
          name = name.slice(3)
          return `element-plus/packages/theme-chalk/src/${name}.scss`;
        },
        resolveComponent: (name) => {
          return `element-plus/lib/${name}`;
        },
      }]
    })
  ]
})
  1. 在main.js中
// 如果要使用.scss样式文件,则需要引入base.scss文件
import 'element-plus/packages/theme-chalk/src/base.scss'
// 改为中文
import locale from 'element-plus/lib/locale/lang/zh-cn'

app.use(Element-plus,{locale})

修改过后,报错消失啦!

PS:如果修改过后报错还未消失,可能是版本问题哦,建议更换版本!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM