Reputation: 5294
Is there any way to exclude certain files or directories from pub publish
for dart packages?
I am publishing a package that has so many screenshots. I want them to upload on GitHub but not on Pub.Dev
. The intention behind this is to reduce the package size.
Upvotes: 12
Views: 3136
Reputation: 9206
If using Flutter, you can now use the assets + flavors possibilities from your pubspec.yaml
file.
For example:
flutter:
assets:
- assets/my_production_assets/ <-- assets available for all builds
- path: assets/my_secret_file.yaml <-- assets only available for internal builds
flavors:
- internal
Here, only the assets/my_production_assets/
files would be included in my release build. my_secret_file.yaml
would only be included into my internal (debug) build.
You can define flavors using the .vscode/launch.json
file if you need or simply using the --flavor [your_environment]
command while building your app (internal
in my example).
Upvotes: 0
Reputation: 1641
Clearing git cache from my PC works for me:
git rm -r --cached .
Upvotes: 6
Reputation: 2070
To expand a little on some of the existing answers, the dart docs state:
All files under the package root directory are included in the published package, with the following exceptions:
- Any hidden files or directories — that is, files with names that begin with dot (.)
- Any directories with the name packages
- Files and directories ignored by a .pubignore or .gitignore file
...
(If a directory contains both a .pubignore file and a .gitignore file, then dart pub publish doesn’t read that directory’s .gitignore file.) The format of .pubignore files is the same as the .gitignore file format
Upvotes: 0
Reputation: 29016
You have three options to exclude files or directories from getting published to pub.dev.
Add your files or directories to .pubignore
or .gitignore
file.
Hide your file or directory by giving it a name which starts with a .
(dot)
Create a new directory with packages
name and put your files there.
If a directory contains both a .pubignore
file and a .gitignore
file, dart pub publish
will not read that directory's .gitignore
file i.e. you can overrule .gitignore
file by creating a .pubignore
file.
Upvotes: 0
Reputation: 813
You can now create a .pubignore
file to do this. See this PR for more details on how this works.
Upvotes: 9
Reputation: 1288
You can add them in .gitignore
while publishing to pub.dev
and later remove from .gitignore
before pushing to GitHub
.
Referenced from dart documentation.
What files are published? All files in your package are included in the published package, with the following exceptions: Any packages directories. Your package’s lockfile. If you aren’t using Git, all hidden files (that is, files whose names begin with .). If you’re using Git, any files ignored by your .gitignore file. Be sure to delete any files you don’t want to include (or add them to .gitignore). pub publish lists all files that it’s going to publish before uploading your package, so examine the list carefully before completing your upload.
Upvotes: 0