I know I can't use them both at once, but is there a way to make .npmignore file extending .gitignore? I have dozens of rules in .gitignore and I want to use them all + one additional for npm package. How can I do it without duplicating all the rules?
.npmignore extending / inheriting from .gitignore
1.5k Views Asked by Daniel Kucal At
2
There are 2 best solutions below
2
On
I don't believe there's any mechanism to do this, but it should be pretty simple to script! Here's how I would tackle this:
Set up a prepack npm script in your package.jsonthat:
- Copies your
.gitignorefile to a.npmignore - Adds your extended rules to the
.npmignorefile after the copy finishes. I would suggest defining these extra rules in a file somewhere, we'll call itextra_rules_filefor clarity in the below example.
Then, optionally a postpack script that deletes your .npmignore now that you don't need it (and maybe don't want to commit it, since it's a generated file)
For example:
package.json
{
"scripts": {
"prepack": "cp .gitignore .npmignore && cat extra_rules_file >> .npmignore",
"postpack": "rm .npmignore"
}
}
extra_rules_file
whatever/rules/you/want/**/*
common-ignore (npm package) looks promising.