2

我试图在 dart 中创建一个“库”类型的项目,然后从另一个项目“依赖”该库(全部使用 yaml 文件的路径依赖功能)。我知道,如果我托管我的库或使用 GIT,我可能能够让依赖项工作,但我也不想这样做,因为我觉得纯基于文件系统的依赖项应该是“不费吹灰之力” .

所以,不用多说,这是我的情况。我有一个非常简单的基于 web_ui 的 dart 库/项目,其中包含两个文件:

esrvdartui.dart
---------------
library esrvdartui;

import 'dart:html';
import 'package:web_ui/web_ui.dart';

part 'esrvradiobutton.dart';



esrvradiobutton.dart
--------------------
part of esrvdartui;

class ESrvRadioButton extends RadioButtonInputElement
{
  ESrvRadioButton ()
  {
  }
}

然后我创建了另一个非常小的/简单的基于 web_ui 的项目,名为“ExampleForm”,它想要使用我上面的 esrvdartui 项目。这两个项目都存在于相同的目录结构中。我的 ExampleForm 项目包含以下 yaml 文件:

pubspec.yaml
------------
name: ExampleForm
description: A sample WebUI application
dependencies:
  js: any
  browser: any
  web_ui: any
  esrvdartui:
    path: ../esrvdartui

无论我在上面的 yaml 文件中将路径设置为什么,我都不会看到我的 ExampleForm 项目下的 web\packages 目录被我的来自 esrvdartui 项目的文件更新,因此,我无法使用我的库中的文件使用基于文件的依赖方法,因为我的 ExampleForm 项目的构建失败。

“Pub install”不会抱怨上面的路径,当我使用绝对路径时它不会抱怨,所以我知道“Pub install”看到我的依赖项目。它只是不会为我复制该死的文件。

有什么想法吗?

ExampleForm 我的 pubspec.lock 文件是:

# 由 pub 生成 # 见http://pub.dartlang.org/doc/glossary.html#lockfile {"packages":{"logging":{"version":"0.5.0+1","source":"hosted","description":"logging"},"source_maps":{"version":" 0.5.0+1","source":"hosted","description":"source_maps"},"unittest":{"version":"0.5.0+1","source":"hosted","描述":"unittest"},"pathos":{"version":"0.5.0+1","source":"hosted","description":"pathos"},"analyzer_experimental":{"version" :"0.4.7+1","source":"hosted","description":"analyzer_experimental"},"web_ui":{"version":"0.4.6+1","source":"hosted","description":"web_ui"},"js":{"version":"0.0.21","source":"hosted","description":"js"},"csslib":{ "version":"0.4.3","source":"hosted","description":"csslib"},"esrvdartui":{"version":"0.0.0","source":"path", "description":{"relative":false,"path":"C:/Users/Jason/dart/esrvdartui"}},"html5lib":{"version":"0.4.3","source":"托管","description":"html5lib"},"args":{"version":"0.5.0+1","source":"hosted","description":"args"},"browser": {"版本":"0.5.0+1","源":"托管","描述":"浏览器"},"元":{"版本":"0.5.0+1","源":"托管","描述":"元"}}}

我的 esrvdartui 的 pubspec.lock 文件是:

由酒馆生成

http://pub.dartlang.org/doc/glossary.html#lockfile

{"packages":{"meta":"version":"0.5.0+1","source":"hosted","description":"meta"},"browser":{"version":"0.5 .0+1","source":"hosted","description":"browser"},"args":{"version":"0.5.0+1","source":"hosted","description ":"args"},"html5lib":{"version":"0.4.3","source":"hosted","description":"html5lib"},"analyzer_experimental":{"version":"0.5 .0+1","source":"hosted","description":"analyzer_experimental"},"csslib":{"version":"0.4.3","source":"hosted","描述":"csslib"},"web_ui":{"version":"0.4.6+1","source":"hosted","description":"web_ui"},"pathos":{"version" :"0.5.0+1","source":"hosted","description":"pathos"},"js":{"version":"0.0.22","source":"hosted"," description":"js"},"source_maps":{"version":"0.5.0+1","source":"hosted","description":"source_maps"},"unittest":{"version" :"0.5.0+1","source":"hosted","description":"unittest"},"logging":{"version":"0.5.0+1","source":"hosted" "描述":"日志记录"}}}

4

1 回答 1

0

我终于让它工作了,但是对于我的一生,我在任何地方都找不到这个记录。您所要做的就是在 Dart IDE 中创建一个项目。然后,在该项目中创建一个名为“lib”的顶级文件夹(除顶级“packages”文件夹之外的所有其他目录)。现在,创建主库的 .dart 文件。我们称之为“mylibrary.dart”。此文件的内容将如下所示:

图书馆.dart

 library mylibrary;

 import 'dart:json';

 part 'src/libraryfile1.dart';

现在,在“lib”下面创建一个子目录来放置你的库的源文件。这实际上可以命名为任何名称,但我选择将其命名为“src”。将你的 libraryfile1.dart 文件放在那里,它应该看起来像这样:

src/libraryfile1.dart

 part of hix_lib;
 .
 .
 .

所有导入语句都应始终放在您的顶级主库文件中:mylibrary.dart。

现在,在您希望在其中使用此基于文件的库的项目中,您必须将“mylibrary”添加到项目的 pubspec.yaml 文件中并选择:“Source: path”。在我的机器上,因为所有项目都在同一个目录中,所以我的路径只是指向:../mylibrary

这就是所有要做的!!!!

于 2013-05-20T16:25:48.017 回答