All Projects → cometkim → nanobundle

cometkim / nanobundle

Licence: MIT license
Yet another build tool for libraries, powered by esbuild

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nanobundle

Pax
The fastest JavaScript bundler in the galaxy.
Stars: ✭ 2,626 (+5735.56%)
Mutual labels:  bundler, commonjs, build-tool
npm-es-modules
Breakdown of 7 different ways to use ES modules with npm today.
Stars: ✭ 67 (+48.89%)
Mutual labels:  commonjs, esmodules, esm
Webpack
A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
Stars: ✭ 60,034 (+133308.89%)
Mutual labels:  commonjs, build-tool, esm
unpack
Create Web apps without a bundler
Stars: ✭ 39 (-13.33%)
Mutual labels:  bundler, esmodules, esm
the-super-tiny-web-module-resolver
simple js bundler written in 100 lines of code.
Stars: ✭ 25 (-44.44%)
Mutual labels:  bundler, commonjs
Parcel
The zero configuration build tool for the web. 📦🚀
Stars: ✭ 39,670 (+88055.56%)
Mutual labels:  commonjs, build-tool
Trunk
Build, bundle & ship your Rust WASM application to the web.
Stars: ✭ 378 (+740%)
Mutual labels:  bundler, build-tool
Neuron.js
A Full Feature CommonJS Module Manager, Dependency Graph Handler and Loader for Browsers
Stars: ✭ 66 (+46.67%)
Mutual labels:  bundler, commonjs
Packem
📦⚡ A precompiled JavaScript module bundler
Stars: ✭ 586 (+1202.22%)
Mutual labels:  bundler, build-tool
Instapack
All-in-one TypeScript and Sass compiler for web applications! 📦 🚀
Stars: ✭ 131 (+191.11%)
Mutual labels:  bundler, build-tool
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (+735.56%)
Mutual labels:  esm, esbuild
awesome-esbuild
A curated list of awesome esbuild resources
Stars: ✭ 195 (+333.33%)
Mutual labels:  bundler, esbuild
Steal
Gets JavaScript
Stars: ✭ 1,353 (+2906.67%)
Mutual labels:  commonjs, build-tool
Pundle
👾 peaceful bundles - js bundler, built from the ground up for speed and extensibility
Stars: ✭ 354 (+686.67%)
Mutual labels:  bundler, build-tool
mock-spy-module-import
JavaScript import/require module testing do's and don'ts with Jest
Stars: ✭ 40 (-11.11%)
Mutual labels:  commonjs, esm
Phaser Node Kit
Rapid Game Development with PhaserJS and Node for Modern Browsers
Stars: ✭ 39 (-13.33%)
Mutual labels:  bundler, build-tool
atbuild
Use JavaScript to generate JavaScript
Stars: ✭ 26 (-42.22%)
Mutual labels:  build-tool, esbuild
Wmr
👩‍🚀 The tiny all-in-one development tool for modern web apps.
Stars: ✭ 4,372 (+9615.56%)
Mutual labels:  build-tool, esmodules
Browserify
browser-side require() the node.js way
Stars: ✭ 13,929 (+30853.33%)
Mutual labels:  bundler, commonjs
tailwind-layouts
Collection of Tailwind Layouts
Stars: ✭ 53 (+17.78%)
Mutual labels:  esm, esbuild

nanobundle

Version on NPM Downlaods on NPM LICENSE - MIT

Yet another build tool for libraries, powered by esbuild

Features

  • Support for ESM and CommonJS
  • Support Import Maps
  • Find and optimize the esbuild options for you
  • Only configuration you need is package.json (and optionally tsconfig.json)

Installation

  1. Install by running yarn add -D nanobundle or npm i -D nanobundle

  2. Setup your package.json:

    {
      "name": "your-package-name",
    
      "source": "./src/foo.ts",        // required, the entry source file
    
      "module": "./dist/foo.mjs",    // where to generate the ESM bundle
      "main": "./dist/foo.cjs",      // where to generate the main entry (CommonJS by default, or ESM if `"type": "module"` and not `*.cjs`)
    
      "imports": {                   // import maps for modules/paths alias
        // ...
      },
    
      "exports": {                   // export maps for multiple/conditional entries
        // ...
      },
    
      "scripts": {
        "build": "nanobundle build"  // compiles "source" to "main"/"module"
      }
    }
  3. Try it out by running yarn build or npm run build

Usage & Configuration

nanobundle is heavily inspired by microbundle, but more daring to try to remove the configuration much as possible. I believe the package.json today is complex enough and already contains most of the configuration for common module use cases.

So attempting to turn users' attention back to the Node's package spec and some meaningful proposals like ES Modules and Import maps which are already supported by Node.js, rather than another custom configuration.

Build targets

nanobundle expects you to write a Web-compatible package.

If you use any Node.js APIs, you need to tell it explicitly via:.

  • Set the entry point with .cjs or .node extension
  • Specify Node.js version via engines field in the package.json

Without engines, the default target will be Node.js v14.

Import Map

nanobundle supports Import maps

You can specify import alias by your package.json, or by a separated json file with the --import-map option.

{
  "imports": {
    "~/": "./",
    "@util/": "./src/utils/",

    // Node.js-style conditional imports
    "#dep": {
      "default": "./dep-polyfill.js",
      "node": "dep-node-native"
    }
  }
}

Export Map

You can specify multiple/conditional entry points in your package.json.

See Node.js docs for more detail.

{
  "type": "module",
  "main": "./main.js",
  "exports": {
    ".": "./main.js",
    "./feature": {
      "default": "./feature.js",
      "node": "./feature-node.js"
    }
  }
}

Embedding dependencies

nanobundle by default does nothing about external like dependencies and peerDependencies.

However, if the --standalone flag is set, it will try to embed all external dependencies into the bundle.

Dependencies specified with --external and Node.js internal APIs are always excluded.

TypeScript

Given a tsconfig.json file in the cwd or --tsconfig option, nanobundle looks for options for TypeScript and JSX.

You can specify declarationDir in your tsconfig, or nanobundle infer the dir from types entry.

nanobundle automatically generate TypeScript declaration as you specify types entry in the package.json, or you can disable it passing --dts=false argument.

Alternatives

  • microbundle : Rollup wrapper that provides similar concept
  • esbuild : This is a simple esbuild wrapper so you can get similar results with just esbuild alone
  • estrella : Build tool based on esbuild
  • tsup : Zero-config bundler based on esbuild

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].