How do I know if a package is dev_dependencies or dependencies?

Asked

Viewed 97 times

2

Taking as the example of this two packages: freezed and freezed_annotation, the installation instruction on the site pub dev. is the same for both packages:

freezed freezed_anotation

However, on video showing how to use this package is shown that freezed is dev_dependencies:

dev_dependencies:
  freezed: ^0.10.6

Not even the Pubspec Assist that if you propose to facilitate installation of dependencies adds the package in the correct location.

How do I know a package is dev_dependencies or dependencies?

3 answers

6


According to the documentation, the rule is simple:

The Rule for Deciding between a regular or dev dependency is simple: If the dependency is Imported from Something in your lib or bin Directories, it needs to be a regular dependency. If it’s only Imported from test, example, etc. it can and should be a dev dependency.

Explaining the sentence above, you will put in dev_dependency only those Packages that you will use only in tests, examples and other things. I mean, you’re just gonna put in dev_dependency those Packages that you will use at development time, things that will not import to a final version...

Practical example

A practical example I can give is Mobx:

We put in dependencies only the Packages

dependencies:
  mobx:
  flutter_mobx: 

And in dev_dependencies, we inform the Packages:

dev_dependencies:
  mobx_codegen:
  build_runner:

When we develop our application using Mobx, we need to use Mobx Widgets and classes to display and control actions from our application, so we import this package directly into dependencies...

But while we’re developing, we need mobx_codegen and build_runner to generate the files *.g.dart to assist in our development, so we just insert these dev_dependencies.

5

The response of Matheus Ribeiro is well written and complete. I believe it should be considered as the best response.

Just supplementing what was explained by him due to a slight (healthy) ambiguity of the question works like this:

  • A package does not have a flag that specifically defines it as being dependencie or dev_dependencie. It is created for one purpose only and the mode of creation is the same for both.

  • When deciding to use that package, the developer configures what it is within your project (as explained by Matheus). So the plugin you quoted has no responsibility to determine if that package is one or the other, it just matters, after that just move it to the correct location.


Update (10/05/2020)

The package quoted in the question now allows you to select whether to add lib to normal or development dependencies. The process is the same, what changes is only that you will choose the location before entering the package name in the search.

2

Another safe source is package documentation (https://pub.dev/), it is very likely that in the documentation you have instructions on installing the package.

site

If you don’t happen to have it, just look for the file pubspec.yaml in the example folder of using the package on github.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.