前言
在使用 element-plus 按需导入,配置 vue.config.js 文件时,报错: ERROR Invalid options in vue.config.js: "plugins" is not allowed。
解决方法:webpack 相关的配置需要写到 configureWebpack 里,不能直接写在外面。
const { defineConfig } = require("@vue/cli-service");
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()],
}),
],
},
});