Unbuild is a robust, unified JavaScript build system leveraging Rollup for efficient bundling. It targets current Node.js and browser environments, producing CommonJS, ES module, and TypeScript declaration outputs. Currently at version 3.6.1, unbuild sees active development with frequent patch and minor releases. Key differentiators include automated configuration inference from `package.json`, support for bundleless distribution via `mkdist`, a passive watcher using `jiti` for rapid development cycles, and integrated 'secure builds' that detect and report missing or unused dependencies. It also features integration with `untyped` for schema generation. While actively maintained, the project has also announced experimentation with `obuild` as a potential next-generation successor, which users should be aware of for future planning.
npm install unbuildVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to set up `unbuild` for a TypeScript project, including `src/index.ts`, the necessary `package.json` fields, an optional `build.config.ts`, and how to trigger the build from the command line.
Monitor announcements from the 'unjs' organization for updates. For projects prioritizing raw build speed or exploring future-proof solutions, consider evaluating 'obuild'.
Thoroughly review `package.json` `dependencies`, `devDependencies`, and `peerDependencies`. Add any genuinely missing packages and remove any that are no longer used by the project to avoid build failures.
After upgrading to v3.5.0 or newer, carefully review the generated `.d.ts`, `.d.mts`, and `.d.cts` files to ensure they align with your project's expected type structure and consumption patterns. Adjust the `declaration` option in `build.config.ts` if needed.
If experiencing issues with `composite` projects, consult the `unbuild` documentation and GitHub issues for the recommended workaround or configuration adjustments for `tsconfig.json` to ensure compatibility.
Carefully choose the `declaration` option value based on your target environment and desired declaration file structure. For modern Node.js environments supporting dual CommonJS and ESM packages, `node16` is often the appropriate choice to generate both `.d.mts` and `.d.cts`.
Update `package.json` to accurately reflect all used dependencies (add missing) or remove unused ones from `dependencies`, `devDependencies`, or `peerDependencies`.
Ensure `build.config.ts` (or equivalent) uses ESM `import` statements (e.g., `import { defineBuildConfig } from 'unbuild';`) and your project is configured for ESM, typically by adding `"type": "module"` to `package.json`.Verify that your `package.json` `exports`, `main`, and `types` fields correctly map to the files generated by `unbuild` (e.g., `dist/index.cjs`, `dist/index.mjs`). Run `npx unbuild` to ensure the build process completes without errors.
Adjust `tsconfig.json`'s `moduleResolution` and `module` options to match your project's target environment. Ensure `esModuleInterop` is enabled if needed, and confirm `unbuild`'s `declaration` option is set appropriately (e.g., `node16` for modern dual package support).