0

Several projects include its source code in the NPM distribution package bundle. For instance, React includes its unminified/unbuilt javascript files in a lib folder but it also has a dist folder with the built files.

Is this a good practice ?

On the downsides I think it increases the time the package will take to be downloaded and the disk consumption. (that's why I usually add source code folders to the .npmignore file)

But I ask myself, why so many libraries do so ? Which are the advantages ?

1 Answers1

2

I'm not sure if this question really falls under something that's asked here on SO, mostly because it's opinion based and could be more of a discussion. But here are my 2 cents anyways:

I believe most of these libraries add their source code (partially because they're open source) to help with debugging purposes. They are typically (but not always) bundled with a .map file as well. Conveniently there's a post that explains what a map file is..

If you think about it like this: anyone who is using your distribution will really only need to install it "once", as in they will probably not be installing it every time they want to use it, but just when they either want to cleanly deploy their project or simply when they install it.

Another thing to think about is: how large is your distribution? Will it really be so big that it will slow down installation time?

As for space a few MB will be negligent on pretty much any modern machine.

I personally think that it's good practice to include the source code as well, I like to know how libraries do what they do, and I like being able to have the option to look into why my code may cause the library to throw errors. But I'm sure there are good reasons not to as well.

tl;dr

  • They do it to help developers debug
  • Unless your project really takes a long time to install, don't worry about it
  • Unless your project is super big, don't worry about it
  • As a dev I like it when projects include it, but "good practice" is quite opinionated and it depends on the situation
Patrick Barr
  • 1,123
  • 7
  • 17
  • Patrick, sorry if I didn't comply with SO rules. Anyway thanks for your answer, it was exactly what I was looking for. – Gustavo Huffenbacher Daud May 22 '17 at 20:38
  • @GustavoHuffenbacherDaud No worries! There's quite a large variety of places on the StackExchange network, it's a confusing place... if I'm not mistaken [https://softwareengineering.stackexchange.com/](https://softwareengineering.stackexchange.com/) would be the place to ask this type of question, if you're looking for a better and more thorough answer I suggest asking it there – Patrick Barr May 22 '17 at 20:52
  • 1
    when referring other sites, it is often helpful to point that [cross-posting is frowned upon](https://meta.stackexchange.com/tags/cross-posting/info) – gnat May 22 '17 at 21:40