3

在我的 Dart 项目中,我需要开始将东西放在单独的文件/包中。我的项目有 2 个需要关注的通用领域,所以似乎需要有 2 个库,分别称为 libA 和 libB,然后是一些通用代码,它们都使用了它们。理想情况下,我需要一个文件和完整的单独项目之间的东西。

我不认为我会想要将它们作为单独的 Pub 导出,但也许......这是否意味着它们应该是库而不是包?Dart 中的库和包之间甚至有区别吗?我需要 3 个不同的完整项目吗?我希望不是。

我想我正在寻找一种在同一个项目中拥有多个本地包的方法。

构建一切的最简单方法是什么?

4

1 回答 1

4

If your code will only be relevant to one project, use one package and multiple libraries. For instance, consider a tower defense game: there will be one package for the whole game, but multiple libraries each dealing with their own areas of concern (enemy lib, tower lib, etc.).

If your code will be relevant to multiple projects but only for your projects (and not the general public), split the code into multiple packages, use local or github pub dependencies, and do not publish them on Pub:

dependencies:
  transmogrify:
    path: /Users/me/transmogrify

See Pub Dependencies for more info.

Continuing the above tower defense example, this would be useful for something like a game studio splash/intro screen. You would want to reuse this across multiple games, but it is not useful for anyone but you.

Finally, if the code can be used for multiple projects, and is of interest to other developers, publish it as a Pub package. For instance, a game engine would be useful to other game developers.

于 2013-08-26T23:14:19.610 回答