2

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.

Titan
  • 5,567
  • 9
  • 55
  • 90

2 Answers2

2

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

Titan
  • 5,567
  • 9
  • 55
  • 90
1

Explicitly adding to files in package.json will force npm pack to include the files

"files": [
    "dist",
    "dist/template/.npmrc",
    "dist/template/.gitignore"
  ]
Steven Than
  • 396
  • 1
  • 2
  • 6
  • or simply use `"files": ["**/*"]`, [ref](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#files) – darkziul Nov 30 '22 at 21:56