按需引入
借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的。
首先,安装 babel-plugin-component:
npm install babel-plugin-component -D
然后,将 .babelrc 修改为:
{ "presets": [["es2015", { "modules": false }]], "plugins": [ [ "component", { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" } ] ] }
masn.js
import { Button, Input, Loading, Message } from "element-ui"; Vue.use(Button) Vue.use(Input) Vue.use(Loading) Vue.prototype.$message = Message; import "@/assets/scss/global.scss"; import 'element-ui/lib/theme-chalk/index.css'; Vue.config.productionTip = false