- All the packages maintained by lerna are placed in
packages
dir. - The main file is
builder.js
here, which is responsible for bundling all the packages into CJS and ESM modules.
- You can follow the lerna guide for adding packages.
- Here are some commands for your reference:
lerna create @your-org/button --yes
: "To add a package",lerna add react --scope=@your-org/button --peer
: "Add react as a peer dependency in your@your-org/button
",lerna add react --scope=@your-org/button --dev
: "Add react as a dev dependency in your@your-org/button
",lerna add @your-org/arsenal --scope=@your-org/{button, dropdown}
: "Add@your-org/arsenal
as a dependency in your@your-org/button
and@your-org/dropdown
package",
-
After creating package with the
lerna create
command, you need to take care of few things in thepackage.json
, so that the bundling process completes without any error.- Change the name of the entry file with the camelCase convention. If you created a package like this:
lerna create @your-org/button --yes // rename button.js to --> Button.tsx lerna create @your-org/dropdown-autosuggest --yes // rename button.js to --> DropdownAutoSuggest.tsx
- Edit the
src
field in the respectivepackage.json
, with the new name of the entry file
// change this { ... other values src: lib/button.js ... other values } // to this { ... other values src: lib/Button.tsx ... other values }
- Add fields for
main
&module
to make an entry point forcjs
andes module
for your package.
// add these fields in your respective `package.json` { ... other values main: dist/index.cjs.js module: dist/index.esm.js ... other values }
- Add fields for
types
&module
for your package.
{ ... other values types: dist/lib/{entry_point_file_name}.d.ts ... other values }
- Add
dist
tofiles
// change this { ... other values files: ['lib'], ... other values } // to this { ... other values files: ['dist', 'lib'], ... other values }
- Now you are ready for bundling your package, prepare for launch 🚀 ;). But if you still have any confusion then you can check the
package.json
of thebutton
component, placed underpackages
.
- To bundle your package individually, run
node builder.js -p {package-name}
- If you want to bundle all your packages together, just run
node builder.js -p all
- After the bundling process is finished, you can find the respective bundled and minified files of the package in
dist
dir.