Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

webpack如何弄个类似lodash的库,支持按需import(可以treeshaking去除冗余代码即可)?

下面是我弄的库:
https://github.com/779102260/...

代码已基本完成,但是就是无法实现按需import

import { isObject } from "kso-util"

目前的思路是

  1. 将所有工具函数都作为入口单独打包,
  2. 给index统一入口也打包一次(同时将所有工具函数作为extrnals排除)

下面是在线demo:https://codesandbox.io/s/kso-...

测试打包,可以看到将所有代码都打包进去了。。
image.png

感觉问题的在于npm包如何支持import导入这块

搞了好几天,吐血了,求大佬们给看看!!!
或者贴下自己的库也行


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

查了各方资料,目前纯webpack还不支持,有个实验性的特性,但有bug

https://github.com/webpack/we...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...