Skip to content

πŸ“¦ The zero-configuration transpiler and bundler for the web

License

Notifications You must be signed in to change notification settings

adbayb/quickbundle

Repository files navigation


πŸ“¦ Quickbundle

The zero-configuration transpiler and bundler for the web


✨ Features

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 and dependencies are not bundled in the final output, devDependencies are unless they're not imported).

πŸš€ Quick Start

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)
	},
	// ...
}
{
	"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

πŸ‘¨β€πŸ³ Patterns

Optimize the build output

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 to false 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

Enable source maps generation

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.


🀩 Used by

  • @adbayb/stack My opinionated toolbox for JavaScript/TypeScript projects.

✍️ Contribution

We're open to new contributions, you can find more details here.


πŸ’™ Acknowledgements

  • 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.

πŸ“– License

MIT.

Footnotes

  1. A module bundler optimized for better tree-shaking processing and seamless interoperability of CommonJS and ESM formats with minimal code footprint. ↩

  2. A TypeScript / JavaScript transpiler for quicker code processing including TypeScript transpilation, JavaScript transformation, and, minification. ↩

About

πŸ“¦ The zero-configuration transpiler and bundler for the web

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •