Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Role of the src and dist folders in NPM packages

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)...

like image 705
Mark Avatar asked Sep 27 '16 15:09

Mark


People also ask

What is src and dist folder?

src/ stands for source, and is the raw code before minification or concatenation or some other compilation - used to read/edit the code. dist/ stands for distribution, and is the minified/concatenated version - actually used on production sites.

What is the role of the src folder?

The /src folder is used to store the file with the primary purpose of reading (and/or editing) the code. The /src folder contains all the sources, i.e. the code which is required to be manipulated before it can be used.

What does dist folder contains in react?

dist stands for distributable, not distribution. It is the directory that once everything ha been compiled, gulped, transpiled, assembled and produced from all the other sources and files and trinkets etc..

What is dist folder in bootstrap?

The dist/ folder includes everything listed in the precompiled download section above. The docs/ folder includes the source code for our documentation, and examples/ of Bootstrap usage. Beyond that, any other included file provides support for packages, license information, and development.


2 Answers

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.

like image 65
DominicValenciana Avatar answered Oct 27 '22 11:10

DominicValenciana


Typically src contains source code and dist code after minification and other changes (anyway, derived code - what would be target in Java world).

Sometimes when main repo is written in EcmaScript6 or newer, then dist folder contains code transpiled down to EcmaScript5 to support older versions of nodejs / older browsers.

You can use code from src if it works for you - however typically code in dist is minified and hence faster.

But sometimes authors forget to update dist folder and then you might have discrepancies. You might ping the author to rebuild the dist folder.

like image 29
jakub.g Avatar answered Oct 27 '22 12:10

jakub.g