vue3按需自动导入组件unplugin-auto-import,vue/cli版本

vue3按需自动导入组件,vue/cli版本

1.安装两个插件

在package.json的devDependencies,然后npm install

 "unplugin-auto-import": "^0.11.2",
 "unplugin-vue-components": "^0.22.7"

2.在vue.config.js中配置

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({

    configureWebpack: (config) => {
        if (!config.plugins) {
            config.plugins = []
        }
        config.plugins.push(
            AutoImport({
                resolvers: [ElementPlusResolver()]
            })
        )
        config.plugins.push(
            Components({
                resolvers: [ElementPlusResolver()]
            })
        )
    }

})

你可能感兴趣的:(vue.js,前端,javascript,elementui)