按需引入
借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的。
首先,安装 babel-plugin-component:
npm install babel-plugin-component -D
然后,将 babel.config.js修改为:
module.exports = {
presets: ["@vue/app"],
plugins:[
[
"component",
{ //这里不需要数组再包着,官方实例有数组包着
"libraryName": "mint-ui",
"style": true
}
]
]
};
如果你只希望引入部分组件,比如 Button 和 Cell,那么需要在 main.js 中写入以下内容:
import Vue from 'vue'
import { Button, Cell } from 'mint-ui'
import App from './App.vue'
Vue.component(Button.name, Button)
Vue.component(Cell.name, Cell)
/* 或写为
* Vue.use(Button)