组件库打包成一个es格式的文件,为何在项目中不能实现按需引入?

70 阅读1分钟

这是vite库模式打包后的es文件,是把多个组件打包成一个文件,下面是打包后的代码,然后在项目里导入 import {EButton} from 'ui-component',然后项目build,查看build后的文件,发现 EInput这个组件也被打进去了,为何此时treeSharking失效了?


import { defineComponent as r, openBlock as s, createElementBlock as p } from "vue";
const a = r({
  name: "ElButton",
  setup() {
  }
}), u = (t, e) => {
  const n = t.__vccOpts || t;
  for (const [o, c] of e)
    n[o] = c;
  return n;
};
function i(t, e, n, o, c, _) {
  return s(), p("div", null, "button");
}
const l = /* @__PURE__ */ u(a, [["render", i]]), d = r({
  name: "ElInput",
  setup() {
  }
});
function $(t, e, n, o, c, _) {
  return s(), p("div", null, "Input");
}
const m = /* @__PURE__ */ u(d, [["render", $]]);
export {
  l as EButton,
  m as EInput
};