Introduction

Pubspec.yaml is the soul of all dart projects. It contains all the dependency information and other meta-information of dart projects, so pubspec.yaml is the meta of dart projects!

Fields supported by pubspec.yaml

According to the definition of dart, pubspec.yaml can contain the following fields:

Field nameIs a field requireddescribe
nameYespackage name
versionIf you publish to pub.dev, you needThe version number of the package
descriptionIf you publish to pub.dev, you needpackage description information
homepagenopackage homepage
repositorynoThe source code address of the package
issue_trackernoPackage issue tracking address
documentationnoDocumentation information for the package
dependenciesnopackage dependency information
dev_dependenciesnopacakge's dev dependency information
dependency_overridesnoThe package you want to cover
environmentdart2 needs
executablesnoThe executable file path of the package
publish_tonoHow will the package be released
Note that the above are the fields supported by pubspec.yaml in dart. If it is in the flutter environment, there will be some additional fields supported.

# one example

Let's look at a specific example:

 name: my_app
version: 11.15
description: >-
  this is a new app
homepage: http://www.flydean.com
documentation: http://www.flydean.com
environment:
  sdk: '>=2.10.0 <3.0.0'
dependencies:
  efts: ^2.0.4
  transmogrify: ^0.4.0
dev_dependencies:
  test: '>=1.15.0 <2.0.0'

Field details

Let's look at the details and restrictions of each field:

  1. Name

The name represents the name of the package. The name must be all lowercase. If there are multiple words, they can be distinguished by underscores, such as: my_app.

And you can only use a combination of lowercase letters and numbers, and you can't start with a number, and don't use reserved words in dart.

  1. Version

Version represents the version number. The version number is three numbers separated by dots, such as 11.15.0. You can also follow the build version number: +1, +2, +hotfix.oopsie, or pre-release version, etc.: -dev.4, -alpha.12, -beta.7, -rc.5.

  1. Description

The description of the package is best described in English, and the length is 60 to 180 characters, indicating the function of the package.

  1. Dependencies

There are two kinds of dependency information, one is the dependency that all people who use this package need to use, and this dependency is placed in dependencies.

There is also a package that is only used in the current pacakge development, and this dependency is placed in dev_dependencies.

In some cases, we may need to override certain dependency packages, which can be placed in: dependency_overrides.

  1. Executables

Some pacakges provide tools for everyone to use. These tools may be command-line tools, so you need to specify the path of the executable command in the executables.

For example, the following configuration:

executables:
  slidy: main
  fvm:

Then after executing pub global activate, you can execute slidy globally to execute bin/main.dart, and fvm to execute binfvm.dart.

  1. environment

Because Dart is a new language, its changes are still quite big for now. So some applications can depend on different dart versions, and environment is needed at this time:

environment:
  sdk: '>=2.10.0 <3.0.0'

In the above code, we specified the version range of the dart sdk.

After dart1.19, environment: also supports specifying the version of flutter:

environment:
  sdk: '>=1.19.0 <3.0.0'
  flutter: ^0.1.2

Summarize

The above is the detailed explanation of dart's metaworld pubspec.yaml.

This article has been included in http://www.flydean.com/10-dart-pubspec/

The most popular interpretation, the most profound dry goods, the most concise tutorial, and many tips you don't know are waiting for you to discover!

Welcome to pay attention to my official account: "Program those things", know the technology, know you better!


flydean
890 声望437 粉丝

欢迎访问我的个人网站:www.flydean.com