14

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

Mark
  • 4,428
  • 14
  • 60
  • 116

2 Answers2

19

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.

DominicValenciana
  • 1,681
  • 2
  • 16
  • 25
  • 1
    You probably meant _de_contaminate. – Stephan Bijzitter Sep 27 '16 at 16:01
  • 1
    Is it common and/or recommended to commit the `dist` folder? – Jared Beck Sep 28 '16 at 17:38
  • 2
    @JaredBeck Honestly it depends on the project. If you are expecting people to work on the project themselves then I wouldn't commit `dist` because it's expected that they build those files them selves using what ever build process you have. If it's the type of project where you want advanced people to contribute and you want newbies to just get the end result and use it without having the hassle of building the project then include your `dist` folder in your repo. – DominicValenciana Sep 28 '16 at 18:33
6

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.

jakub.g
  • 38,512
  • 12
  • 92
  • 130