自动按需导入官网教程
首先:npm install -D unplugin-vue-components unplugin-auto-import
然后配置webpack.config.js
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
module.exports = {
// ...
plugins: [
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
}
也可以直接配置babel.config.js,但是如果安装版本过高可能在配置时会报错,所以安装指定版本
npm i element-plus@1.0.2-beta.28
module.exports = {
plugins: [
[
'import',
{
libraryName: 'element-plus',
customStyleName: (name) => {
return `element-plus/lib/theme-chalk/${name}.css`
}
}
]
],
}
按照官网自动按需导入element-plus出现以下问题:样式不生效
将安装版本更换为npm i element-plus@1.0.2-beta.28