[英]Dart package layout
I just read Dart's suggested packagout layout spec and have a few questions regarding it: 我刚刚阅读了Dart建议的packagout布局规范,并提出了一些问题:
lib
directory. lib
目录。 But running pub get
or pub upgrade
will fetch those packages into a packages
directory. pub get
或pub upgrade
会将这些包提取到packages
目录中。 So which is it?!? pub get
, pull down packages into packages
, and then manually copy them over to lib
? pub get
,将包下拉到packages
,然后手动将它们复制到lib
? That seems inefficient! lib
, but that internal packages (not a part of the API) should go in lib/src
. 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! main()
methods? main()
方法吗? Why/why not? packages/**
build/**
(produced by pub build
) build/**
(由pub build
) pubspec.lock
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
文件的dependencies
或dev_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)
pub *
) pub *
)
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.