# 按需引入
使用按需引入,需要配合插件 babel-plugin-component
,只需要引入需要的组件,以达到减小项目体积的目的。
首先项目安装 babel-plugin-component:
npm install babel-plugin-component -D
在项目中的 .babelrc
或 babel.config.js
中修改为:
{
"presets": [...],
"plugins": [
[
"component",
{
"libraryName": "mist-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
改完后,在 main.js
中,引入需要使用的组件,例如 Button 和 Link:
import Vue from 'vue';
import { Button, Link } from 'mist-ui';
import App from './App.vue';
Vue.use(Button);
Vue.use(Link);
new Vue({
el: '#app',
render: h => h(App)
});