Klap is a zero-configuration, zero-dependency bundler designed for small to medium-sized JavaScript packages. It simplifies the build process by leveraging standard `package.json` entries (`source`, `main`, `module`, `browser`) to define multiple output targets, including CommonJS, ESM, and UMD. Despite its "zero dependency" marketing claim, it internally integrates and orchestrates established tools such as Rollup, Babel, and TypeScript to provide modern JavaScript syntax transforms, JSX support (for frameworks like React, Styled Components, and Emotion), and TypeScript compilation. The current stable version is 7.0.11, though the last significant update to the main GitHub repository was in May 2021, suggesting a maintenance or stable state rather than active, frequent development. Key differentiators include built-in minification, gzip size tracking, and a development server, offering an opinionated, complete build pipeline with minimal setup for library authors.
npm install klapVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a TypeScript project with JSX support using `npx klap init tsx`, create a simple React component and a utility function, set up a local development server for testing, and finally build the library for distribution. It showcases `klap`'s zero-config approach for common library development patterns, particularly for React-based packages.
Carefully review your bundled output after upgrading to v7.0.0+ if your library targets Node.js environments or uses Node.js global variables. Adjust your code or `klap` configuration if unexpected behavior or runtime errors occur due to changed global polyfills.
Evaluate the project's long-term viability for your needs. If continuous updates, robust community support, or bleeding-edge feature compatibility are critical, consider alternative, more actively maintained bundlers.
Be aware that major version upgrades of `klap` are most likely to incorporate significant updates to these internal dependencies. Review `klap`'s changelog carefully for details on underlying tool versions and their potential impact.
Ensure your entry point file has the correct `.ts` or `.tsx` extension. For advanced TypeScript configurations, you might need to simplify your `tsconfig.json` to align with `klap`'s conventions or consider a bundler that offers more explicit TypeScript configuration options.
Ensure your `package.json` includes valid `source`, `main`, `module`, and `browser` entries, even if you intend to only output a subset of formats. Running `npx klap init` is the recommended way to generate a correct minimal `package.json`.
Install TypeScript as a development dependency: `npm install --save-dev typescript`. Verify your Node.js version is compatible with the installed `klap` and `typescript` versions. Using `npx klap init ts` or `npx klap init tsx` should prompt for its installation.
For React/JSX projects, initialize with `npx klap init tsx`. Ensure your source files containing JSX or other advanced syntax have the correct `.jsx` or `.tsx` (for TypeScript with JSX) extension, as `klap` relies on these for automatic detection and transformation.
Review your code for direct usage of Node.js globals. If they are necessary for browser compatibility, you might need to manually provide polyfills or ensure your code is environment-aware. This error is more prevalent after upgrading to v7.0.0 due to the change in the `nodeGlobals` plugin.
No dependency data recorded yet.