pubspec.yaml中的配置标志如何工作?

问题描述 投票:6回答:1

我正在学习Flutter和Dart。我注意到thepubspec.yaml文件似乎不仅包含第三方库的依赖版本。例如。

# The following section is specific to Flutter.
flutter:
  uses-material-design: true

据我所知,Dart Pub Tool定义了pubspec.yaml的格式,看起来像Flutter这样的框架可以通过额外的设置来增强pubspec.yaml,提出以下问题:

  • pubspec.yaml是否被设计用于提供配置标志或仅用于依赖?
  • 颤抖的方式是使用pubspec.yaml惯用的Dart还是独一无二的?
  • pubspec.yaml是仅由pub工具解析还是在运行时作为通用应用程序配置文件解析?
  • Flutter是否为pubspec.yaml实现了自己的解析器,并在运行时提供uses-material-design: true等设置?
dart flutter dart-pub flutter-dependencies
1个回答
5
投票

pubspec.yaml是否设计用于提供配置标志或仅提供依赖项?

从历史上看,它还包含纯Dart项目中的构建设置。例如,编译为JS的设置,但已移至build.yaml。见https://github.com/dart-lang/build/blob/master/build_config/README.md

颤抖的方式是使用pubspec.yaml惯用的Dart还是独一无二的?

这是Flutter独有的。

Flutter是否为pubspec.yaml实现了自己的解析器,并在运行时提供uses-material-design: true等设置?

是。

这些设置是构建时设置,而不是运行时设置。


实际上我发现这个文件混合了不同的目的是相当不幸的。在Flutter早期,Flutter特定的设置在不同的文件中,但这也造成了一些困难(不知道细节 - 只在GitHub讨论中看到它),所以他们将它与pubspec.yaml合并。

© www.soinside.com 2019 - 2024. All rights reserved.