Quickbundle allows you to bundle a library in a quick, fast and easy way:
- Fast build and watch mode powered by Rollup1 and SWC2.
- Zero configuration: define the build artifacts in your
package.json
, and you're all set! - Support of
cjs
&esm
module formats output. - Support of several loaders including JavaScript, TypeScript, JSX, JSON, and Images.
- TypeScript's declaration file (
.d.ts
) bundling. - Automatic dependency inclusion (
peerDependencies
anddependencies
are not bundled in the final output,devDependencies
are unless they're not imported).
1οΈβ£ Install by running:
# Npm
npm install quickbundle
# Pnpm
pnpm add quickbundle
# Yarn
yarn add quickbundle
2οΈβ£ Set up your package configuration (package.json
):
- When exporting exclusively ESM format:
{
"name": "lib", // Package name
"exports": {
".": {
"source": "src/index.ts(x)?", // Source code entry point.
"types": "./dist/index.d.ts", // Typing output file (if defined, can increase build time). This condition should always come first after the custom `source` field definition.
"default": "./dist/index.mjs", // By default, Quickbundle will always output ESM format for the `default` field (this condition should always come last since it always matches as a generic fallback). However, take care: if both `import` and `default` fields are defined, provide the same file path, as the `import` field export instruction will be the only one considered to define the output file path.
},
"./otherModulePath": {
// ...
}
}
"scripts": {
"build": "quickbundle build", // Production mode (optimizes bundle)
"watch": "quickbundle watch", // Development mode (watches each file change)
},
// ...
}
- When exporting both CommonJS (CJS) and ECMAScript Modules (ESM) format (please be aware of dual package hazard risk):
{
"name": "lib", // Package name
"exports": {
".": {
"source": "src/index.ts(x)?", // Source code entry point.
"types": "./dist/index.d.ts", // // Typing output file (if defined, can increase build time). This condition should always come first after the custom `source` field definition.
"require": "./dist/index.cjs", // CommonJS output file (matches when the module is loaded via require() consumer side).
"import": "./dist/index.mjs", // ESM output file (matches when the package is loaded via import or import() consumer side).
"default": "./dist/index.mjs", // By default, Quickbundle will always output ESM format for the `default` field (this condition should always come last since it always matches as a generic fallback). However, take care: if both `import` and `default` fields are defined, provide the same file path, as the `import` field export instruction will be the only one considered to define the output file path.
},
"./otherModulePath": {
// ...
}
}
"scripts": {
"build": "quickbundle build", // Production mode (optimizes bundle)
"watch": "quickbundle watch", // Development mode (watches each file change)
},
// ...
}
3οΈβ£ Try it by running:
# Npm
npm run build
# Pnpm
pnpm build
# Yarn
yarn build
By default, Quickbundle does the following built-in optimizations during the bundling process:
- Include, in the build output, only the code that is effectively imported and used in the source code. Setting the
sideEffects
package.json field tofalse
marks the package as a side-effect-free one and helps Quickbundle to safely prune unused exports. - Identify and annotate side-effect-free code (functions, ...) to enable a fine-grained dead-code elimination process later consumer side. For example, if a consumer uses only one library API, build output annotations added by Quickbundle allow the consumer's bundler remove all other unused APIs.
However, Quickbundle doesn't minify the build output. Indeed, in general, if the build targets a library (the most Quickbundle use case), minification is not necessary since enabling it can introduce some challenges:
- Reduce the build output discoverability inside the
node_modules
folder (minified code is an obfuscated code that can be hard to read for code audit/debugging purposes). - Generate suboptimal source maps for the bundled library, as the consumer bundler will generate source maps based on the already minified library build (transformed code, mangled variable names, etc.).
- Risk of side effects with double optimizations (producer side and then consumer side).
Popular open source libraries (Vue, SolidJS, Material UI, ...) do not provide minified builds as the build optimization is sensitive to the consumer context (e.g. environment targets (browser support), ...) and needs to be fully owned upstream (i.e. consumer/application-side).
However, for non-library targets or if you would like to minify the build output on your side anyway, Quickbundle still provides the ability to enable the minification via:
quickbundle build --minification
quickbundle watch --minification
By default, source maps are not enabled but Quickbundle still provides the ability to enable it via:
quickbundle build --source-maps
quickbundle watch --source-maps
Enabling source map generation is needed only if a build is obfuscated (minified) for debugging-easing purposes. It generally pairs with the minification
flag.
- @adbayb/stack My opinionated toolbox for JavaScript/TypeScript projects.
We're open to new contributions, you can find more details here.
- The backend is powered by Rollup and its plugin ecosystem (including SWC) to make blazing-fast builds. A special shoutout to all contributors involved.
- The zero-configuration approach was inspired by microbundle. A special shoutout to its author Jason Miller and all contributors.
MIT.
Footnotes
-
A module bundler optimized for better tree-shaking processing and seamless interoperability of CommonJS and ESM formats with minimal code footprint. β©
-
A TypeScript / JavaScript transpiler for quicker code processing including TypeScript transpilation, JavaScript transformation, and, minification. β©