I just want to clear my concepts? I'm using a npm
package named reactstrap which is installed on node_modules
folder. The package contains 4 folders.
I know src
folder contains the source code of the library but what is the difference between other these 3 folders.
What if I write something like this to import a component.
import {Button} from 'reactstrap';
The above line is using ES6 module
syntax to import a component.
Does this Button component is came from the es
folder or lib
folder?
What will be the syntax if I want to import the Button
component by using commonJS module
pattern?
lib – Application specific libraries. Basically, any kind of custom code that doesn't belong under controllers, models, or helpers. This directory is in the load path. That's not particularly helpful. By using the word “libraries” in the definition, it's recursive.
The lib folder has the JavaScript code that provides the nice set of modules that are included by default with every Node. js installation. The src folder contains the C++ libraries for libuv.
In a typical "universal JS" app 3rd party libraries are kept in node_modules and /lib is used for your own code that does not require compilation. / src would be used for ES6 code that needs to be "compiled" ("transpiled")
The lib folder is what package. json main points to, and users that install your package using npm will consume that directly.
When use import/require
an package without specify an filepath, npm will use main
file that was specify in package.json (reactstrap package.json). it's same for es and commonJS style.
'es', 'dist', 'lib',... is just folders that was built by different options, so it's just an optional for each project with specific usecase. You can see build option for each type here.
As you can see, dist folder was created by rollup, it let this package runable on browser, es module and commonJs module. And lib folder was created by babel
If 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