Adding Packages
When adding packages to your Dart projects, there are two ways in which these
packages can be referenced inside your pubspec.yaml
.
Adding a package from pub.dev
To add a package from pub.dev π, you can simply add the package
name to the dependencies
section of your pubspec.yaml
file.
For a list of all the packages which are publicly available on pub.dev
, refer
to the article on packages.
Adding a package from the Enterprise Plan Package Registry
Adding a package from the private pub registry requires you to set up a token
for the hosted provider. You will get this token
during the onboarding process
for the enterprise plan. Once you have this token, you can add the hosted
provider as below.
-
Keep the details handy
Keep the details of the hosted provider handy. You will need the URL of the hosted provider and the token to authenticate the requests. Letβs capture these with the following variables for rest of the steps:
<token>
: secret token to authenticate requests to the hosted provider<private-pub-registry>
: URL of the hosted provider
-
Add the hosted provider
Use the
<token>
given to you during the onboarding stage and enter that as your secret token. -
Add the package to your
pubspec.yaml
You can now add the package from the hosted provider like so:
An easier way is to just copy this snippet for each enterprise package and paste into your
pubspec.yaml
: -
Bootstrap with Melos
Now when you run
melos bootstrap
inside your project, the package will be fetched from the hosted provider.
Summary
This guide covers how to add packages from both the public and private package
registries. The private package registry requires you to set up a token for the
hosted provider. Once done you can add the package to your pubspec.yaml
and
run melos bootstrap
to fetch the package.