Node: How to handle your dist files
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 …
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?