Invalid options in vue.config.js: “plugins“ is not allowed

2023-05-06 21:35:31 浏览数 (1)

vue3按需导入element plus出现错误

1、错误详情

在使用vue3根据官方文档按需自动导入element plus,配置 vue.config.js 文件时出现Invalid options in vue.config.js: "plugins" is not allowed错误。 具体如下所示:

2、解决办法

webpack 相关的配置需要写到 configureWebpack 里,不能直接写在外面。 如下配置示例:

代码语言:javascript复制
const { defineConfig } = require('@vue/cli-service')
//auto import element plus components
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
  },
})

0 人点赞