ElementUI / babel-plugin-component

Modular element-ui build plugin for babel.
452 stars 96 forks source link

我在使用vue的SSR案例时,使用babel,总会把所有插件都打包。 #16

Open zhump opened 7 years ago

zhump commented 7 years ago

app.js 中没有使用 element-ui 插件

import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router'
import { sync } from 'vuex-router-sync'
import * as filters from './filters'
sync(store, router)

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
const app = new Vue({
  router,
  store,
  render: h => h(App)
})
export { app, router, store }

Demo.vue 使用了 Button, Message两个组件

<template>
  <el-button :plain="true" @click="open">打开消息提示</el-button>
</template>

<script>
import Vue from 'vue'
import {
  Button,
  Message
} from 'element-ui'
Vue.use(Button);
Vue.prototype.$message = Message
  export default {
    methods: {
      open() {
        this.$message('这是一条消息提示');
      }
    }
  }
</script>

实际打包 其实把element-ui 所有的代码都打包了,并且 没有样式文件?求教,我该怎么做才能做到按需打包?

.babelrc

{
  "presets": [
    ["es2015", { "modules": false }]
  ],
  "plugins": [["component", [
    {
      "libraryName": "element-ui",
      "styleLibraryName": "theme-default"
    }
  ]]]
}
Super-Mouse commented 6 years ago

+1