• Stars
    star
    183
  • Rank 205,859 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

zero config, zero dependency bundler for tiny javascript packages

klap ๐Ÿ‘

a zero config, zero dependency bundler for tiny javascript packages.

Build Status David David npm NPM All Contributors

klap output

โœจ Features

  • ๐ŸŽ‰ zero config: bundle your library using only a package.json
  • ๐Ÿ’ฅ zero config: typescript support (just rename *.js to *.ts)
  • ๐ŸŒŸ zero config: code transforms using babel macros
  • ๐ŸŒˆ zero config: code generation using babel plugin codegen
  • ๐Ÿš€ zero dependency: uses gcc-style bundling.
  • ๐Ÿ™ creates tiny bundles for multiple output formats cjs, esm and umd
  • ๐Ÿ”ฅ Modern JS syntax with class properties, async/await, and generators
  • โšก Built in Minification and Gzip Size Tracking
  • ๐ŸŒ€ Built in development server for quick prototyping.
  • ๐ŸŽŠ Supports react, styled-components and emotion out of the box.

๐Ÿ’ช Powered By

  • rollup - Next-generation ES module bundler
  • babel - The compiler for next generation JavaScript
  • typescript - Typed JavaScript at Any Scale.

๐Ÿฝ๏ธ Usage

First, initialize your project using klap init:

npx klap init

Prefer Typescript ? initialize using ts argument:

npx klap init ts

Want to use JSX with Typescript? init using tsx argument:

npx klap init tsx

The init command will create a minimal package.json with source, main, module and browser entries and the build, watch and start scripts.

{
  "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.main will disable cjs output, also applies to esm and umd outputs.

Then use npm run or yarn to invoke npm scripts as you normally would.

See examples for common use cases using klap.

๐Ÿ’ข Granular Control

klap uses sensible defaults for most part. However, as needed, use below properties in package.json to fine tune klap. You can also use cli flags to 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 umd bundles 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.js or 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.pragma --pragma the JSX Pragma for classic runtime react
klap.pragmaFrag --pragmaFrag JSX Fragment pragma react
klap.usets --usets use typescript compiler for the project false
klap.globals global names for umd bundles {}

--usets allows the library code to use typescript features not supported by @babel/preset-typescript. See const-enums example to enable usage of const enums.

๐Ÿฅ‚ License

klap is licensed under the MIT License.

Documentation is licensed under Creative Common License.

Created with โค๏ธ by @osdevisnot and all contributors.

โœจ 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!

๐Ÿ’ Supporters

More Repositories