Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.npmignore extending / inheriting from .gitignore

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?

like image 225
Daniel Kucal Avatar asked Jun 06 '17 21:06

Daniel Kucal


1 Answers

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:

  1. Copies your .gitignore file to a .npmignore
  2. Adds your extended rules to the .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:

package.json

{
  "scripts": {
    "prepack": "cp .gitignore .npmignore && cat extra_rules_file >> .npmignore",
    "postpack": "rm .npmignore"
  }
}

extra_rules_file

whatever/rules/you/want/**/*
like image 163
Hawkins Avatar answered Oct 08 '22 01:10

Hawkins