dart - 在 dart 库中导入包时出现 Linter 警告

标签 dart dart-polymer

我正在开发一个大型 Dart 项目,其中包括一个 Web 前端以及几个自定义库。我们正在使用推荐的文件夹结构,如here所述。 .

my_app/
    lib/
        my_library1/
            example/
            lib/
                my_library1.dart
                my_library1.html
            pubspec.yaml
        ...
    web/
    pubspec.yaml

我们的 lib 文件夹中有几个库,我们都将它们导入到主 pubspec.yaml 中,如下所示:

dependencies:
  my_library1:
    path: lib/my_library1

这一切都工作得很好,但是当我使用 pub build 生成 JS 构建时,我收到了大量有关如何为我们拥有的每个库正确导入包的 Linter 警告。

例如,my_library1 库在 my_library1.html 文件中有一个聚合物导入,如下所示:

<link rel="import" href="../../packages/polymer/polymer.html">

对此的警告是:

[Warning from polymer (Linter) on my_app|lib/my_library1/lib/my_library1.html]:
line 1, column 1 of lib\my_library1\lib\my_library1.html: Invalid URL to reach to another package: ../../packages/polymer/polymer.html. Path reaching to other packages must first reach up all the way to the packages directory. For example, try changing the URL to: ../../../../packages/polymer/polymer.html. See http://goo.gl/5HPeuP#code_transformers_2 for details.
<link rel="import" href="../../packages/polymer/polymer.html">
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

现在,如果我将该行更改为他们建议的内容 (../../../../packages/polymer/polymer.html),我会收到此错误:

[Warning from polymer (Linter) on my_library1|lib/my_library1.html]:
line 1, column 1 of lib\my_library1.html: Invalid URL to reach to another package: ../../../../packages/polymer/polymer.html. Path reaching to other packages must first reach up all the way to the packages directory. For example, try changing the URL to: ../../packages/polymer/polymer.html. See http://goo.gl/5HPeuP#code_transformers_2 for details.
<link rel="import" href="../../../../packages/polymer/polymer.html">
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

所以无论我怎么做,都是错误的。有趣的是,警告的源文件从 my_library1|lib\my_library1.html 更改为 my_app|lib\my_library1\lib\my_library1.html

这对任何人都有意义吗?

顺便说一句,我一直在各个 Dart 网站( #1#2#3 )上阅读这些内容,但没有结果。

我正在使用 Dart 1.7.2(稳定)和聚合物 0.15.3+2

最佳答案

您的包不应包含多个 pubspec.yaml 文件。 lib/文件夹应该只包含 dart 文件和其他资源,例如 html、js 和 css 文件。例如,您可以按如下方式组织您的项目:

 my_app/
     lib/
        my_library1/
            my_library1.dart
            my_library1.html
        ...
     web/
     pubspec.yaml //you do not need to include my_library1 as a dependency here

此外,如果你想在其他包中使用my_library1,你需要将其移动到自己的包中:

 my_library1/
     example/
     lib/
         my_library1.dart
         my_library1.html
     pubspec.yaml
 my_app/
     lib/
         ...
     web/
     pubspec.yaml //you need to include my_library1 as a dependency here

无论哪种情况,my_library1.html 都可以使用以下导入:

 <link rel="import" href="../../packages/polymer/polymer.html">

关于dart - 在 dart 库中导入包时出现 Linter 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27714414/

相关文章:

dart - 聚合物 paper_input 的数据绑定(bind)不起作用

dart - 在 polymer 网格布局中自动调整 Canvas 大小

dart - 聚合物元素中没有阴影根

Dart 覆盖一元减号运算符

dart - 父小部件的 setState 不会更新子部件的值

Flutter:使用 Dart 检查设备可用存储

android - 无法选择 Flutter Dropdownbutton 的项目

dart - 区分同一元素上的 onClick 和 onDoubleClick 以在 Dart 中执行不同的操作

dart - Dart- polymer 单元测试。点击事件后无法引用dom元素

dart - 为什么我的Dart/Polymer自定义元素渲染没有?