Open FoneQinrf opened 2 years ago
This is not a bug cause by this plugin. it is caused by the code
import { Loading } from 'element-ui'
To resolve it, you can import babel-plugin-component
or change the import code to(which is the same logic for babel-plugin-component
implement)
import Loading from 'element-ui/lib/loading'
昨天也遇到这个问题,其实issue里已经解答了,不过提问的人说的比较笼统。 在vite里配置了这个插件之后,.vue的template里使用Element-ui就不用再走import->配Component的路线了,比如:
<template>
<!-- 直接能显示,不用import了 -->
<el-icon name="close" class="close-icon" ></el-icon>
</template>
<script>
// import {ElIcon} from 'element-ui'; <--这里再引入会重新沿着element-ui/index.js打包一遍,导致按需引入失败
export default {
components: {
},
}
</script>
<style scoped>
</style>
但是,插件只会匹配template中的元素,再给它加上对应的import;js里Vue.use(Loading)
你再import { Loading } from 'element-ui'
,插件压根不会处理,所以还是得手动用按需引入import Loading from 'element-ui/lib/loading'
Describe the bug
使用该插件按需引入element-ui,打包后把element-ui全量打包了,并未按需打包。
Reproduction
https://github.com/FoneQinrf/vite-vue2
System Info
Used Package Manager
yarn
Validations