Node: How to handle your dist files

Ikechi Michael
2 min readFeb 9, 2018

--

NPM loves you … no, really … come back, it’s true!

When building JavaScript modules, you may have to transpile/compile them with build tools like browserify, or babel.

This will generate dist files, which we point to as the “main” property in our package.json …

our generated file

This means that the generated build file becomes the entry point into our module.

But we can’t add the generated build file to source-control, can we?

No, we shouldn’t!

Never add generated files to source control

Go to your .gitignore file and be sure to ignore those generated files, or its entire folder.

dist

How then, do our users get our dist files when they install our module from NPM?

In your package.json, you can add a “files” property which has an array value and link to the generated files to include them when publishing our package to NPM.

{
"main": "dist/index.js",
"files": [
"dist/index.js"
]
}

Now, your dist files won’t disturb you and your team in source-control, yet your users will have them when you publish.

Cool, huh?

--

--

Ikechi Michael
Ikechi Michael

Written by Ikechi Michael

I’ve learned I don’t know anything. I've also learned that people will pay for what I know. Maybe that's why they never pay.

Responses (1)