Dan*_*cal 9 git gitignore npm package.json npmignore
我知道我不能同时使用它们,但有没有办法使.npmignore文件扩展.gitignore?我有几十个规则.gitignore,我想全部使用它们+一个额外的npm包.如何在不重复所有规则的情况下完成这项工作?
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:
.gitignore file to a .npmignore.npmignore file after the copy finishes. I would suggest defining these extra rules in a file somewhere, we'll call it extra_rules_file for 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:
{
"scripts": {
"prepack": "cp .gitignore .npmignore && cat extra_rules_file >> .npmignore",
"postpack": "rm .npmignore"
}
}
Run Code Online (Sandbox Code Playgroud)
whatever/rules/you/want/**/*
Run Code Online (Sandbox Code Playgroud)