如何为Dart创建库?

10

我该如何使用Dart创建库?

我想开始将我创建的一些JavaScript(和其他语言)库移植到Dart。

2个回答

12

只需将以下内容放入您的库文件中(第一行):

library mylibraryname;

然后你可以使用以下命令导入该库:

import "path/to/mylibraryname.dart";

还有其他选项可供选择,例如part,它可以充当包含文件的作用。

如果需要更深入的教程,我建议您阅读这篇来自Dartwatch的博客文章


2
库文件名必须与其声明的库名匹配吗?例如,如果我在文件中声明“库foo”,那么文件的名称必须为“foo.dart”吗? - devdanke
7
链接似乎已经失效了 :( - romanos

1

stagehand 是最简单的。

使用方法

mkdir fancy_project
cd fancy_project
stagehand package-simple

舞台技术模板

console-full - A command-line application sample.
package-simple - A starting point for Dart libraries or applications.
server-shelf - A web server built using the shelf package.
web-angular - A web app with material design components.
web-simple - A web app that uses only core Dart libraries.
web-stagexl - A starting point for 2D animation and games.

安装

如果您想在命令行上使用Stagehand,请使用pub global activate进行安装:

pub global activate stagehand

此项目(stagehand)已被停止。 - Pedro Luz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接