简体   繁体   English

是不是推荐使用TypeScript / Angular 2+中的桶或最佳做法?

[英]Are barrels in TypeScript / Angular 2+ not recommended or best practice?

I've read several times that barrels are not recommended by Angular, but I'm not seeing that officially anywhere. 我已多次读过Angular不推荐使用的桶,但我没有在任何地方看到它。 And on the Angular site I see where they say they are using them. 在Angular网站上,我看到他们说他们正在使用它们。

https://angular.io/guide/glossary#B https://angular.io/guide/glossary#B

UPDATE: In an apparent update to the Angular documentation, the page I've linked to doesn't appear to mention barrels anymore. 更新:在对Angular文档的明显更新中,我链接到的页面似乎不再提及桶。 If anyone can find where they say they use those, or an example of such usage, please comment with a link. 如果有人可以找到他们说的地方,或者使用这些用法的例子,请用链接评论。

Using Barrel exports are absolutely fine (it is just a way to simplify your import process) 使用Barrel导出绝对没问题(这只是简化导入过程的一种方法)

If AOT compiler is not complaining about the build then it is fine. 如果AOT编译器没有抱怨构建,那么它没问题。

you can read more about that here 你可以在这里阅读更多相关信息

https://medium.com/@adrianfaciu/barrel-files-to-use-or-not-to-use-75521cd18e65 https://medium.com/@adrianfaciu/barrel-files-to-use-or-not-to-use-75521cd18e65

https://basarat.gitbooks.io/typescript/docs/tips/barrel.html https://basarat.gitbooks.io/typescript/docs/tips/barrel.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM