加载elementor时出现问题_element-ui按需加载问题.

今天发现这么一个现象,两份在我看来并无差别的代码,按需加载效果不一致。

一份能在打包时按需加载(chunk-vendors.hash.js小)。

另一份看大小像是全局引入(无论我引入多少个组件打包后的大小不会有变化)。

初始化时会在main.js中引入plugins/index.js

关键代码如下:

1. 无法按需加载的代码// plugins/element.js

import "element-ui/lib/theme-chalk/index.css"

export {

Button,

Form,

FormItem,

Input,

Card,

Row,

Col,

Table,

TableColumn,

Pagination

} from "element-ui";// plugins/index.js

import Vue from "vue";

import * as ElementComponents from "./element";

// 这里ElementComponents确实是只有我需要的组件

Object.keys(ElementComponents).forEach(name => {

Vue.use(ElementComponents[name]);

});

2. 能正常按需加载的代码// plugins/element.js

import "element-ui/lib/theme-chalk/index.css"

import Vue from "vue";

import {

Button,

Form,

FormItem,

Input,

Card,

Row,

Col,

Table,

TableColumn,

Pagination

} from "element-ui";

[

Button,

Form,

FormItem,

Input,

Card,

Row,

Col,

Table,

TableColumn,

Pagination

].forEach(item => Vue.use(item));// plugins/index.js

import Vue from "vue";

import "./element.js";

有没有老哥知道差别在哪?

======================================================

我使用vant试了一下相同写法, 是能正常按需加载的 使用的是babel-plugin-import

element-ui使用的是babel-plugin-component其forked自babel-plugin-import

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值