Moshe Katz Moshe Katz - 1 year ago 54
Git Question

Make my NPM package available in source and dist versions

I am working on a private NPM package that I make available to developers who use our API. For various reasons (decided by management), the package on our NPM repository (Sonatype Nexus) has the following folder structure:

+- build
| |- browser.min.js
| \- node.min.js
|- docs
| \ ...
|- package.json

The JS files in the
directory are compiled from the actual code of the package.

Also included in the built package are specific versions of dependencies that the package relies on (such as a modified version of

To allow for easy publishing, the
has the following in it:

"main": "build/node.min.js",
"browser": "build/browser.min.js",
"files": [

However, for internal use of the package, we want to use an uncompiled version, specifically to reduce the overhead of included our dependencies that were included above.

(Aside, I know that this isn't necessarily the best way to package stuff, but we can't change that so easily at this point unless we have no other option.)

I assumed that I would be able to pull the package from our private Git repository, which would give me the whole code of the package.

However, NPM still reads the
section of
when it loads from Git, so it does the
git clone
and then deletes any files that are not present in the
array, leaving me with a directory that contains only
, and

Is there a way to get the entire code of the package checked out of Git and kept?

Answer Source

In the end, I decided to modify my build process to make this easier.

Instead of building just the scipts into the build directory and packaging starting from the repository root directory, I have modified my build script to also copy, package.json, and docs/* into the build directory, then to cd into that directory to do the npm publish.

That way, package.json can just say to include all files in the directory.