npmnpm-publishnpm-pack

npm pack/publish won't pack .gitignore or .npmrc files


I have built a project generator for my company. It's a globally installed npm package, that when run, takes the entire contents of a /template directory inside the package and copies it to the user's chosen destination.

Inside /template I have 2 files that npm pack refuses to include in the final published module:

/template/.gitignore

/template/.npmrc

Everything else, including other hidden files, get packed as expected.

These 2 files are not in any root (or nested) .gitignore files, and I'm not manually specifying any files array in any package.json that npm might pick up on.


Solution

  • This is intentional behaviour https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package

    The workaround was to create .gitignore.template and rename on install