简体   繁体   English

飞镖包布局

[英]Dart package layout

I just read Dart's suggested packagout layout spec and have a few questions regarding it: 我刚刚阅读了Dart建议的packagout布局规范,并提出了一些问题:

  1. The spec says that I should put all 3rd party packages into a lib directory. 规范说我应该将所有第三方包放入lib目录。 But running pub get or pub upgrade will fetch those packages into a packages directory. 但是运行pub getpub upgrade会将这些包提取到packages目录中。 So which is it?!? 那是哪个?!? Am I supposed to run pub get , pull down packages into packages , and then manually copy them over to lib ? 我应该运行pub get ,将包下拉到packages ,然后手动将它们复制到lib That seems inefficient! 这似乎效率低下!
  2. The spec says that packages that should be a part of an API should go in lib , but that internal packages (not a part of the API) should go in lib/src . 规范说应该是API的一部分的包应该放在lib ,但是内部包(不是API的一部分)应该放在lib/src So if my project depends on some 3rd party package called transmogrify , how do I known which transmogrify packages are a part of the public API and should be placed in lib , and which ones are "private" and should be placed in lib/src ? 因此,如果我的项目依赖于一些名为transmogrify第三方软件包,我怎么知道哪些transmogrify软件包是公共API的一部分,应该放在lib ,哪些是“私有的”,应该放在lib/src This seems tedious! 这看起来很乏味!
  3. Can a Dart app have 2+ main() methods? Dart应用程序可以有2个以上的main()方法吗? Why/why not? 为什么/为什么不呢?
  4. Just want confirmation that the following files should not be checked into a VCS: 只是想确认应该将以下文件签入VCS:
    • packages/**
    • build/** (produced by pub build ) build/** (由pub build
    • pubspec.lock
    • Any others? 还有其他人?
  1. When you run pub-get, it pulls all required packages into your packages directory. 当您运行pub-get时,它会将所有必需的包拉入您的packages目录。 Leave the structures untouched. 保持结构不变。
  2. My suggestion is to use the package names you can find in "Add package" when you open the pubspec.yaml file in Dart Editor. 我的建议是在Dart编辑器中打开pubspec.yaml文件时使用“添加包”中可以找到的包名。
  3. No. main() is the program entry point. 编号main()是程序入口点。 So one program, one entry. 所以一个程序,一个条目。
  4. That is pretty much you have listed. 这几乎是你列出的。 To add one: .buildlog. 添加一个:.buildlog。

1) you don't put 3rd party packages into a lib directory. 1)您不将第三方软件包放入lib目录。

If you want to build a reusable library package you put the files building the library in the lib directory. 如果要构建可重用的库包,请将构建库的文件放在lib目录中。

3rd party packages are just referenced in the dependencies or dev_dependencies section in the pubspec.yaml file. 第三方包仅在pubspec.yaml文件的dependenciesdev_dependencies部分中pubspec.yaml The rest is maintained by pub . 其余的由pub维护。

2) should be partly answered by 1). 2)应部分回答1)。 You put your public surface of your library package into lib. 您将库包的公共表面放入lib中。 Library internals that should not be exposed as public API can/should go into a lib sub directory. 不应作为公共API公开的库内部可以/应该进入lib子目录。

3) I think this depends how you specify a Dart app. 3)我认为这取决于你如何指定Dart应用程序。 A Dart package can certainly have several main functions. Dart包当然可以有几个主要功能。 You can't have more entry pages in the web directory where each has a main. 您不能在web目录中有更多的条目页面,每个条目都有一个main。

You can have more Dart script files in bin, test, example where each can have a main. 你可以在bin,test,example中有更多的Dart脚本文件,其中每个文件都有一个main。

You start an app by opening an entry page in the browser or running a script file with dart myscript.dart so this clearly defines what gets called. 您可以通过在浏览器中打开一个入口页面或使用dart myscript.dart运行脚本文件来启动应用程序,这样就可以明确定义调用的内容。

4) 4)

  • you don't check in packages/ 办理入住套餐/
  • you don't check in build/ 签入建立/
  • you do check in pubspec.lock for application packages 可以在pubspec.lock中查看应用程序包
  • you don't check in pubspec.lock for library packages also take a look at this question In Dart and Pub, should I add pubspec.lock to my .gitignore? 没有检查pubspec.lock的库包也看看这个问题在Dart和Pub中,我应该将pubspec.lock添加到我的.gitignore吗?
  • I have several in .gitignore but they seem not to be used anymore (at least not by pub * ) 我有几个.gitignore但它们似乎不再被使用(至少不是由pub *
    • out
    • deploy 部署
    • _from_packages _from_packages

I somehow have the impression that you are mixing up the concepts of libraries and packages. 我不知何故给你的印象是你混淆了库和包的概念。 Just to clarify: You can have more than one library inside on package. 只是为了澄清:你可以在包装里面放置多个库。 You can (or have to) import individual libraries of a package individually if you want to use them. 如果要使用它们,您可以(或必须)单独导入包的各个库。

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

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