我正在创建一个 dart http 库库用于 flutter 应用程序。 我从 < a href=" https://pub. dev/packages/http# configiforation" rel= "nofollown noreferrer" > >here 中学习到, 每个不同的平台都需要不同的 http 客户端执行, 如 cronet_http/code >,
cupertino_http < /code>,
,
fetch_client
。 所以我必须在软件包 s pubspec.yaml
中包括所有可能的依附关系, 并使用有条件的导入。
问题是,如果我只想在某个平台上发布我的应用程序,不管是它还是机器人。 iOS和网络的依赖性会被纳入他的应用程序吗? 如果是的话,应用程序的大小将会不必要地大于要求。
编辑 :
It s hard to check whether the unnecessary dependencies included
or not, because for cronet_http
or cupertino_http
, i think it s only about several bytes in size. So instead, i am trying to derive the conclusion that, if cupertino_http
is not used in the finally released Android app, but it s included, it will be certainly increase the size of the app by some extent. Do i have to really make an app for this library and check whether it s several bytes larger than expected, so that i am qualified to ask my question?
我想象到,可以采取如下一种办法,排除不必要依赖性:
- specify
cronet_http
andcupertino_http
as optional dependencies, like there isandroid_dependencies
, orios_dependencies
, besidesdependencies
inpubspec.yaml
. - And let the library users select which dependency to include in his/her release, with the
dependencies
.
或者在 dev_dependies
中保留可选择的依存关系,并可选择检测和导入包含的依存关系,然后让用户在 dependies
中选择哪个。
很高兴知道有一个treshashking
algo在摇摆中去掉这些不必要的依赖代码。但我很难从谷歌找到一些关于它的文件。只有几个博客讨论它,只是更混乱一些,比如