There are many popular JavaScript libraries and applications on GitHub and some put their raw source code in a /src
directory, and others in a /lib
directory.
I'm leaning towards the developers having done this depending on which languages they were taught growing up. So I see a lot of Java developers use /lib
(who also normally end up putting their packaged JS into a /bin
directory). Meanwhile I often observe that those who use /src
output their packaged JS into a /dist
folder instead.
What is considered the standard pattern for JavaScript, src
or lib
. Maybe there isn't a right or wrong answer at all.
/lib or /vendor - suggested putting your libraries which is not required for compilation. /src - for your code source.
lib is short for library which is often used for common files, utility classes, imported dependencies, or 'back in the days' also for dlls for (desktop) applications. It's in general a 'library' of supporting code for the core application.
lib & src. The difference in using lib vs src should be: lib if you can use node's require() directly. src if you can not, or the file must otherwise be manipulated before use.
The /lib directory contains kernel modules and those shared library images (the C programming code library) needed to boot the system and run the commands in the root filesystem, ie. by binaries in /bin and /sbin. Libraries are readily identifiable through their filename extension of *. so.
Interesting question, but it seems to me that some developers just take it by their own worldview.
It also depends on the project:
Some projects are built with smaller components, which are just little pieces of the main functionality: lib
.
lib/independent-pieces.js
Other projects are monolithic, the components depend on each other: src
.
src/this-is-all-for-this-project-and-depend-on-each-other.js
For third-party libraries, it's common to use vendor
.
vendor/bootstrap/ vendor/d3/
/node_modules
- for 3rd party libraries./lib
or /vendor
- suggested putting your libraries which is not required for compilation./src
- for your code sourceIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With