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

Recommendation: whitelist instead of blacklist

Answering the use case, I would instead recommend explicitly white listing what you want to publish with the files entry in package.json, rather than blacklisting with .npmignore, as that makes it is much more likely that you will not accidentally publish the wrong files. See also: https://medium.com/@jdxcode/for-the-love-of-god-dont-use-npmignore-f93c08909d8d

Here's a concrete example package which looks a bit like:

{
  "files": [
    "gitignore",
    "cirodown",
    "cirodown.js",
    "cirodown.embed.min.css",
    "cirodown.local.min.css",
    "cirodown.min.css",
    "index.js",
    "main.liquid.html",
    "main.scss",
    "nodejs.js"
  ],
}

Yes, it is working using glob patterns : https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package

But I would have a different approach :

dist/*
dist/.*
!dist/file.js

in order to no ignore the whole folder but it's content (the 2nd line may not be required).