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.

By default those files are left out because they are (usually) about developing your package and not part of the package published contents. See:

https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package

You might be able to explicitly include them, but I suggest a safer and common practice is to name them differently when they are in the template folder and then rename them when you are copying as part of the generator. This makes it explicitly that they are templates and do not serve their normal purpose in the template directory itself.

e.g.

/template/.gitignore-template
/template/.npmrc-template

Thanks I was hoping to avoid it, but thanks for confirming it’s not possible!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.