Questions tagged [npmignore]

The `*.npmignore` file is used to keep stuff out of programmed package.

Use a .npmignore file to keep stuff out of your package. If there's no .npmignore file, but there is a file, then npm will ignore the stuff matched by the .gitignore file. If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it.

.npmignore files follow the same pattern rules as .gitignore files:

  • Blank lines or lines starting with # are ignored.
  • Standard glob patterns work.
  • You can end patterns with a forward slash / to specify a directory.
  • You can negate a pattern by starting it with an exclamation point !.
22 questions
110
votes
5 answers

Should I .npmignore my tests?

What exactly should I put in .npmignore? Tests? Stuff like .travis.yml, .jshintrc? Anything that isn't needed when running the module (except the readme)? I can't find any guidance on this.
callum
  • 34,206
  • 35
  • 106
  • 163
44
votes
1 answer

Should package-lock.json also be published?

npm 5 introduced package-lock.json, of which the documentation is here. It states that the file is intended to be included with version control, so anyone cloning your package and installing it will have the same dependency versions. In other words,…
wybe
  • 615
  • 5
  • 14
33
votes
1 answer

What's the difference between .npmignore and .gitignore?

What's the difference between .npmignore and .gitignore? What kind of files should I ignore in each?
Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
23
votes
2 answers

How can I whitelist a single file in a directory in .npmignore?

I'm trying to make npm download only a single file in a directory on npm install of the package. The directory looks like: +- dist/ +- 1.0.0/ +- 1.0.1/ +- ...lots of other dirs... +- file.js I want npm to ignore everything but file.js…
m90
  • 11,434
  • 13
  • 62
  • 112
20
votes
1 answer

npm link does not care for "files" in package.json or .npmignore

My goal is to specify what files will be included in my node module before publishing it and be able to test the installation locally. Using the "files" in the package.json works in that if I publish my package and install it, then I get only what…
Arman
  • 2,665
  • 3
  • 14
  • 19
10
votes
2 answers

.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…
Daniel Kucal
  • 8,684
  • 6
  • 39
  • 64
8
votes
2 answers

How to debug .npmignore?

How can package files (these to be published) be listed to debug records in .npmignore? I'm looking for something like equivalent of git ls-files for .gitignore. The only way I have found so far is to pack the package and then list the archive which…
czerny
  • 15,090
  • 14
  • 68
  • 96
7
votes
1 answer

Load an npm package from local directory without copying unnecessary files/folders such as node_modules

Let's imagine I have to develop an npm package, my-package, which needs to be imported and used by my-project. While developing my-package I need to install and use other packages from npm. At the end of the development of my-package, I bundle all…
Picci
  • 16,775
  • 13
  • 70
  • 113
7
votes
1 answer

.npmignore - Ignore all *.ts files but not *.d.ts

I am looking for a good way to ignore all .ts files in a project when I publish to NPM, I can do that by adding the following to my .npmignore file: *.ts but wait..actually I want to keep all the .d.ts files in my project, when I publish... What…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
5
votes
1 answer

.npmignore: ignore whole folder except given file types

Background I have a typescript project that I am publishing to npm. All my TS sources are in a folder called src and these are compiled to a folder called dist. src is likely to include some html templates, possibly css files and other assets. As…
Roaders
  • 4,373
  • 8
  • 50
  • 71
3
votes
1 answer

Do I need to copy-paste stuff form ".gitignore" to ".npmignore"

So I was reading this. And I'm a bit confuse how it's works, as I understood it: If I only have .gitignore in my repo npm will use .gitignore but If I have both .gitignore and .npmignore npm will only read .npmignore, right? Or it will read…
Bromer
  • 53
  • 2
3
votes
0 answers

yarn publish .gitignore overriding .npmignore

I'm trying to publish a module I have created. The module has multiple entries in it and I want to publish from within my build folder. Every time I try to publish with yarn. I get: Output: The following paths are ignored by one of your…
Jony-Y
  • 1,579
  • 1
  • 13
  • 30
3
votes
1 answer

Should I commit auto generated files published in npm package

I have a NPM package written in TypeScript. My build process takes all *.ts files and bundle them into myLib.d.ts, myLib.js and myLib.js.map. My NPM package must have all src/.ts files and these three myLib. auto generated files. But in my git…
lmcarreiro
  • 5,312
  • 7
  • 36
  • 63
2
votes
1 answer

`npm publish` ignoring new additions to .npmignore

While building create-near-app, artifacts get created within the project tree. Some of these were added to a .npmignore file, but others were missed until I attempted to publish a new version and noticed that the npm package would be several hundred…
chadoh
  • 4,343
  • 6
  • 39
  • 64
2
votes
1 answer

Should I npmignore ".github" folder?

Should I npmignore .github folder which contains stuff need for Github Actions? Also side question. Do I need to push .npmignore to github?
Bromer
  • 53
  • 2
1
2