zero config, zero dependency bundler for tiny javascript packages
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<!-- prettier-ignore-end -->
package.json
*.jsto
*.ts)
cjs,
esmand
umd
react,
styled-componentsand
emotionout of the box.
First, initialize your project using
klap init:
npx klap init
Prefer Typescript ? initialize using
tsargument:
npx klap init ts
Want to use JSX with Typescript?
initusing
tsxargument:
npx klap init tsx
The
initcommand will create a minimal
package.jsonwith
source,
main,
moduleand
browserentries and the
build,
watchand
startscripts.
{ "name": "...", "version": "0.0.0", "files": [ "dist" ], "source": "src/sum.js", # source file of your package "main": "dist/sum.cjs.js", # commonjs bundle target "module": "dist/sum.esm.js", # esm bundle target "browser": "dist/sum.js", # umd bundle target "scripts": { "build": "klap build", # bundle your package "watch": "klap watch", # bundle your package and watch for changes "start": "klap start", # start a development server }, "devDependencies": { "klap": "3.2.0" # klap as dev dependency } }
Note: Dropping
pkg.mainwill disablecjsoutput, also applies toesmandumdoutputs.
Then use
npm runor
yarnto invoke npm scripts as you normally would.
See examples for common use cases using
klap.
klapuses sensible defaults for most part. However, as needed, use below properties in
package.jsonto fine tune
klap. You can also use
cli flagsto control config options for
klap.
| option | cli flag(s) | description | default | | ---------------- | ---------------------- | ---------------------------------------------- | ------------------------------------------------------------- | |
source| -s --source | source file to compile and bundle |
src/index.js| |
cjs| -c --cjs | the output file for common js format | pkg.main | |
esm| -e --esm | the output file for esm format | pkg.module | |
umd| -u --umd | the output file for umd format | pkg.browser | |
types| -t --types | the output file for type definitions | pkg.types | |
browserslist| -b --browserslist | browserslist compatible compilation target |
last 2 versions modern browsers if usage is greater than 1%| |
klap.name| -n --name | package name for
umdbundles | sanitized
pkg.name| |
klap.port| -p --port | port for development server |
1234| |
klap.example| --example | location of index js/ts file for start command |
public/index.jsor
pkg.source| |
klap.fallback| --fallback | location of index html file for start command |
public/index.html| |
klap.target| --target | target for development server (
umd, es) |
es| |
klap.sourcemap| --no-sourcemap | sourcemaps for builds |
true| |
klap.minify| --no-minify | minification for builds |
true| |
klap.runtime| --runtime | the runtime for new JSX transform |
react| |
klap.globals| | global names for umd bundles |
{}|
klap is licensed under the MIT License.
Documentation is licensed under Creative Common License.
Created with ❤️ by @osdevisnot and all contributors.
Thanks goes to these wonderful people (emoji key):
v 1 r t l 💻 |
Daniel Berner 💻 |
Tom Julius 💻 |
Marcus Lindblom 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
klapwith an open source license.