CLI Reference

Complete command-line interface documentation

CLI Reference

Packem exposes four commands: build, init, add, and migrate. Run them through your package manager, for example npx packem build or pnpm exec packem build.

packem build

Build the package using the resolved packem configuration.

packem build [options]

General options

FlagTypeDescription
--dir <path>stringThe directory to build. Defaults to ..
--config <path>stringUse a custom config file.
--tsconfig <path>stringPath to the tsconfig.json file.
-t, --target <env>stringEnvironments to support. The target in tsconfig.json is added automatically; defaults to the current Node.js version.

Output options

FlagTypeDescription
--minifybooleanMinify the output.
--sourcemapbooleanGenerate source maps (experimental).
--dts-onlybooleanOnly generate .d.ts files.
--no-cleanbooleanDo not clean the dist directory before building.
--unbundlebooleanPreserve the source file structure instead of bundling into a single file.
--exebooleanBundle the output into a standalone executable via Node.js SEA (requires Node.js >= 25.7.0, single entry).
--runtime <runtime>node | browserSpecify the build runtime.
--bundler <bundler>rollup | rolldownSpecify the bundler to use.
--cjsInteropbooleanCJS interop mode — can export default and named exports (experimental).

Development options

FlagTypeDescription
--watchbooleanWatch for changes and rebuild. Conflicts with --jit.
--jitbooleanStub the package for JIT compilation. Conflicts with --watch.
--onSuccess <command>stringExecute a command after a successful build (especially useful in watch mode).
--killSignal <signal>SIGTERM | SIGKILLSignal used to kill the onSuccess child process.

Environment options

FlagTypeDescription
--productionbooleanRun in the production environment. Conflicts with --development.
--developmentbooleanRun in the development environment. Conflicts with --production.
--env.<KEY>=<value>repeatableCompile-time environment variables, e.g. --env.NODE_ENV=production.
--env-file <path>stringPath to a .env file to load environment variables from.
--env-prefix <prefix>stringPrefix for environment variables loaded from the .env file. Defaults to PACKEM_.

CLI environment variables override values loaded from a .env file. The --env flag splits on the first =, so values that contain = (such as URLs with query strings) are preserved.

Analysis options

FlagTypeDescription
--analyzebooleanVisualize and analyze the bundle (writes packem-bundle-analyze.html). Conflicts with --watch.
--metafilebooleanGenerate a metadata JSON file per bundle (experimental).
--typedocbooleanGenerate type documentation.
--license <path>stringPath to the license file.

Dependency options

FlagTypeDescription
--external <list>repeatableMark a dependency as external. Comma-separated, e.g. --external lodash,react.
--no-externalbooleanDo not bundle external dependencies.

Other flags

FlagTypeDescription
--no-validationbooleanDisable output validation.
--no-cachebooleanDisable the file cache.

--no-validation overrides validation supplied by a preset, but not validation you set explicitly in packem.config.ts.

Examples

# Build for production (minifies automatically)
packem build --production

# Watch with development environment
packem build --watch --development

# Inject a compile-time variable
packem build --env.API_URL=https://api.example.com

# Use the experimental rolldown bundler
packem build --bundler rolldown

packem init

Initialize packem configuration. Runs an interactive wizard that detects your project and writes a packem.config.ts (or .js) file.

packem init [options]
FlagTypeDescription
--dir <path>stringThe directory to initialize. Defaults to ..
--transformer <name>esbuild | swc | sucraseChoose a transformer.
--runtime <runtime>node | browserSpecify the build runtime.
--cssbooleanSet up CSS support.
--css-minifierbooleanSet up a CSS minifier.
--typescriptbooleanUse TypeScript.

The wizard asks about TypeScript, the build runtime, the transformer, and optional CSS loaders/minifiers, installs the matching dependencies, and writes the config file.

packem add

Add an optional feature to an existing packem project. The feature is passed as an argument and the command edits your existing config file in place.

packem add <feature> [options]

Supported features: typedoc, react, solid, preact, vue, svelte, css.

FlagTypeDescription
--dir <path>stringThe project directory. Defaults to ..
--config <path>stringUse a custom config file.

Framework features (react, solid, preact, vue, svelte) add the matching preset to your config and install the required dependencies. css runs an interactive loader/minifier selection. typedoc wires up the TypeDoc builder.

npx packem add react
npx packem add css
npx packem add typedoc

If the git working tree has uncommitted changes, add asks for confirmation before editing the config, since the edit cannot be cleanly undone otherwise.

packem migrate

Migrate a project from another bundler (tsup, unbuild, bunchee) to packem. The command rewrites bundler dependencies and package.json build scripts to use packem.

packem migrate [options]
FlagTypeDescription
--cwd <path>stringThe directory to migrate. Defaults to ..
--dry-runbooleanPreview changes without applying them.

migrate modifies your files and warns that uncommitted changes may be lost. Use --dry-run first to preview the changes. Bundler config files (such as tsup.config.ts) are reported but not migrated automatically — they require manual conversion to packem.config.ts.

# Preview the migration
packem migrate --dry-run

# Apply the migration
packem migrate

Next steps

Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues