Loading...

vue-cli3 使用mint-ui

关于vue-cli3.x按需引入mint-ui问题记录:

按需引入
借助 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)
 * Vue.use(Cell)
 */

new Vue({
  el: '#app',
  components: { App }
})

参考文档:

vue-cli3.x  https://cli.vuejs.org/config/#pluginoptions

mint-ui  http://mint-ui.github.io/docs/#/zh-cn2/quickstart

posted @ 2018-08-28 16:09  微笑阳光哈*_*  阅读(6926)  评论(1编辑  收藏  举报