Exports
Generate exports
field in package.json
file. This field is used to specify the entry points of a package. Generally, it is used to define the main file of a package, and define the sub-path entries of the package.
Command
bash
monopkg info exports [paths...] [options]
bash
bun x monopkg info exports [paths...] [options]
bash
npx monopkg info exports [paths...] [options]
bash
yarn dlx monopkg info exports [paths...] [options]
Options
-m
,--module
<modules...>
- Exported modules (esm, cjs, dts, svelte).-s
,--source
<path>
- Source directory to scan the exportable folders (default:src
).-o
,--output
<path>
- Output directory for the entry point (default:dist
).-f
,--filter
<packages...>
- Include specific packages.-e
,--exclude
<packages...>
- Exclude specific packages.-w
,--workspace
<workspaces...>
- Root workspaces of the packages.--wildcard
- Add wildcard exports for sub-path entries.
NOTE
- The
esm
module is used for ES module exports, it's theimports
field in each export entry, andmodule
field in thepackage.json
. - The
cjs
module is used for CommonJS module exports, it's therequire
field in each export entry, andmain
field in thepackage.json
. - The
dts
module is used for TypeScript declaration file exports, it's thetypes
field in each export entry, andtypes
field in thepackage.json
. - If both
esm
andcjs
modules are used, thecjs
entry will point to.cjs
files, and theesm
entry will point to.js
files. - If your package has
typescript
as a dependency, thedts
module will be automatically generated.
Examples
bash
monopkg info exports core auth --module esm cjs dts --wildcard
bash
bun x monopkg info exports core auth --module esm cjs dts --wildcard
bash
npx monopkg info exports core auth --module esm cjs dts --wildcard
bash
yarn dlx monopkg info exports core auth --module esm cjs dts --wildcard
This command generates the exports
field in the package.json
for the core
and auth
folder in the src
directory. The output will be like this:
package.json
json
{
"name": "example",
"version": "1.0.0",
"description": "Example package",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"./": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./auth": {
"types": "./dist/auth/index.d.ts",
"import": "./dist/auth/index.js",
"require": "./dist/auth/index.cjs"
},
"./auth/*": "./dist/auth/*",
"./core": {
"types": "./dist/core/index.d.ts",
"import": "./dist/core/index.js",
"require": "./dist/core/index.cjs"
},
"./core/*": "./dist/core/*"
},
"dependencies": {
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/lodash": "^4.14.168"
}
}
TIPS
The easiest way to generate the exports
field is using the interactive mode. Run the command without any arguments, and it will prompt you to select the packages and modules you want to export.