Role of the src and dist folders in NPM packages

Mark picture Mark · Sep 27, 2016 · Viewed 10.5k times · Source

Im using Restangular for HTTP requests. I want to use the method customPATCH. I can see it in the Restangular src/ directory here.

However when I ran 'npm install restangular' and pointed to the dist/ folder, I was getting the error "customPATCH is not a function". I noticed the source code in the dist/ folder isnt the same as what's in the src/ folder (it doesnt define the customPATCH method).

Why would there be a difference between what's in src/ and what's in dist/ for an NPM package? Are these normally kept in sync? In this case, the dist/ directory hasn't been updated in 8 months. Should I just use the source in the src/ folder? Maybe I'm misunderstanding how to use NPM packages (I always use the source in the dist/ folder)...

Answer

DominicValenciana picture DominicValenciana · Sep 27, 2016

src/ and dist/ is a common naming convention for most packages. In most instances a developer has the code that they are working on src/ and the distribution version of the code they want others to use dist/. Most developers, my self included will either compile, minify or concatenate their code in to production facing version of the code. They usually include the src/ file in their public repositories so that people can see the source code and modify it as they see fit.

tdlr;

src/is the code the developer is working in.

dist/ is the distribution version that has been modified to perform better for users not looking to modify how the code works.