TypeError: AutoImport is not a function
原因:unplugin-auto-import
插件版本问题
Vue3基于Webpack,在vue.config.js中配置
- 当
unplugin-vue-components
版本小于0.26.0时,使用以下写法
javascript
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()],
}),
]
}
})
- 当
unplugin-vue-components
版本大于等于0.26.0时,使用以下写法
javascript
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.default({
resolvers: [ElementPlusResolver()],
}),
Components.default({
resolvers: [ElementPlusResolver()],
}),
]
}
})