I'm curious about why some repositories include a dist folder. Shouldn't repositories just store source code and not any builds or compiled files?
Let's take a look at an example with ES6 code.
package.json
{
"files": [
"dist",
"lib"
],
"scripts": {
"build:lib": "<transform ES6 to ES5 and put it in the ./lib folder>",
"build:umd": "<create a umd module and place it in the ./dist folder>",
"build": "npm run build:lib && npm run build:umd",
"postbuild": "<minify code>"
"prepublish": "npm run build"
}
}
This approach makes sense to me, and I have seen other repositories follow a similar structure. With this setup, the GitHub repo only contains src
, while the npm repo includes only lib
and dist
.
Now onto another question: Why include dist
and lib
in npm? Most libraries can be easily installed with the command npm install
. Additionally, we know that the prepublish
script runs on local npm install
(see npm-scripts). After installing a package, we already have the lib
and dist
folders. So why include this compiled code in npm when the source code is sufficient?