Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between lib and es folder

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.

  • dist
  • es
  • lib
  • src

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?

like image 832
Timmy Mucks Avatar asked Oct 17 '19 04:10

Timmy Mucks


People also ask

What is a lib folder?

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.

What is Lib folder in Nodejs?

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.

What is Lib folder in JS?

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

What is the lib folder NPM?

The lib folder is what package. json main points to, and users that install your package using npm will consume that directly.


1 Answers

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

like image 177
Hung Nguyen Avatar answered Oct 09 '22 09:10

Hung Nguyen