Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adbayb/quickbundle
📦 The zero-configuration transpiler and bundler for the web
https://github.com/adbayb/quickbundle
library
Last synced: 3 months ago
JSON representation
📦 The zero-configuration transpiler and bundler for the web
- Host: GitHub
- URL: https://github.com/adbayb/quickbundle
- Owner: adbayb
- License: mit
- Created: 2021-03-22T21:42:17.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-07T23:59:54.000Z (3 months ago)
- Last Synced: 2024-11-08T00:31:52.446Z (3 months ago)
- Topics: library
- Language: TypeScript
- Homepage:
- Size: 2.07 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-esbuild - quickbundle - configuration bundler for JavaScript and TypeScript libraries producing optimized CommonJS and ESM NPM modules. (JavaScript Ecosystem)
README
📦 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 Rollup[^1] and SWC[^2].
- 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).[^1]: A [module bundler](https://rollupjs.org/) optimized for better tree-shaking processing and seamless interoperability of CommonJS and ESM formats with minimal code footprint.
[^2]: A [TypeScript / JavaScript transpiler](https://swc.rs/) for quicker code processing including TypeScript transpilation, JavaScript transformation, and, minification.
## 🚀 Quick Start
1️⃣ Install by running:
```bash
# 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:
```jsonc
{
"name": "lib", // Package name
"type": "module", // Optional if you want Node-like runtime to process by default `.js` file as ESM modules.
"sideEffects": false, // Mark the package as a side-effect-free one to support the consumer dead-code elimination (tree-shaking) process. If your library contains global side effects (ideally, it should be avoided), configure the field to list the files that do have side effects.
"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](https://nodejs.org/api/packages.html#dual-package-hazard)):
```jsonc
{
"name": "lib", // Package name
"type": "module", // Optional if you want Node-like runtime to process by default `.js` file as ESM modules.
"sideEffects": false, // Mark the package as a side-effect-free one to support the consumer dead-code elimination (tree-shaking) process. If your library contains global side effects (ideally, it should be avoided), configure the field to list the files that do have side effects.
"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:
```bash
# 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](https://rollupjs.org/configuration-options/#treeshake-annotations) 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](https://unpkg.com/browse/[email protected]/dist/), [SolidJS](https://unpkg.com/browse/[email protected]/dist/), [Material UI](https://unpkg.com/browse/@material-ui/[email protected]/), ...) 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:
```bash
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:
```bash
quickbundle build --source-maps
quickbundle watch --source-maps
```Enabling source map generation is needed only if a build is [obfuscated (minified)](#optimize-the-build-output) for debugging-easing purposes. It generally pairs with the [`minification` flag](#optimize-the-build-output).
## 🤩 Used by
- [@adbayb/stack](https://github.com/adbayb/stack) My opinionated toolbox for JavaScript/TypeScript projects.
## ✍️ Contribution
We're open to new contributions, you can find more details [here](./CONTRIBUTING.md).
## 💙 Acknowledgements
- The backend is powered by [Rollup](https://github.com/rollup/rollup) and its plugin ecosystem (including [SWC](https://github.com/swc-project/swc)) to make blazing-fast builds. A special shoutout to all contributors involved.
- The zero-configuration approach was inspired by [microbundle](https://github.com/developit/microbundle). A special shoutout to its author [Jason Miller](https://github.com/developit) and [all contributors](https://github.com/developit/microbundle/graphs/contributors).
## 📖 License
[MIT](./LICENSE "License MIT").