esbuild

repository·main·Indexed 12 days ago

https://github.com/evanw/esbuild

An extremely fast JavaScript bundler and minifier designed for high build tool performance. It supports bundling JavaScript, TypeScript, JSX, and CSS, and provides features such as tree shaking, source maps, and a plugin system. esbuild is available via a CLI, JS, and Go API, and offers extensive platform-specific binaries and WebAssembly shims for various architectures including Windows, macOS, Linux, Android, and others.

Tokens
96.2K
Snippets
367
Records
603
Agent score
98%

What's inside esbuild

  1. Overview of @esbuild/linux-mips64el

    main
    The @esbuild/linux-mips64el package provides the Linux MIPS 64-bit Little Endian binary for esbuild. esbuild is a high-performance JavaScript bundler and minifier. This specific package is a platform-specific distribution intended for environments running on Linux with a MIPS 64-bit Little Endian architecture.
  2. Overview of esbuild

    main
    esbuild is a high-performance JavaScript bundler and minifier. It is designed to be extremely fast and can be used via a Command Line Interface (CLI) or through its JavaScript API to bundle, minify, and transform JavaScript, TypeScript, and other web assets.
  3. Overview of esbuild features

    main

    esbuild is an extremely fast JavaScript bundler designed to improve build tool performance. It provides high speed without requiring a cache and supports a wide range of modern web technologies out of the box.

    Key Features:

    • Built-in Support: JavaScript, CSS, TypeScript, and JSX.
    • Module Support: Bundles both ESM and CommonJS modules.
    • CSS Capabilities: Bundles CSS, including support for CSS modules.
    • Optimization: Includes tree shaking, minification, and source maps.
    • Developer Experience: Provides a CLI, JS, and Go API, as well as a local development server, watch mode, and a plugin system.
  4. Use the esbuild WebAssembly shim for Android ARM

    main
    The @esbuild/android-arm package provides a WebAssembly (Wasm) shim for running esbuild on Android devices with ARM architecture. This allows esbuild functionality to be available in environments where a native binary might not be directly executable or available.
  5. Use the esbuild WebAssembly shim for Android x64

    main
    The @esbuild/android-x64 package provides a WebAssembly (Wasm) shim for running esbuild on Android devices with x64 architecture. This allows you to leverage esbuild's bundling capabilities in environments where a native binary might not be directly available or easily executable.
  6. How build and transform operations differ

    main

    esbuild's API is divided into two primary operations based on your use case:

    1. Build: Reads from the file system and writes back to the file system. Use this when you want to take advantage of esbuild's full bundling capabilities (resolving dependencies, tree shaking, etc.).
    2. Transform: Takes an input string and generates an output string. Use this when integrating esbuild as a library inside another tool, such as a minification plugin or a custom compiler step.

    Both operations are available via the CLI and as a library (JavaScript, Go, and Browser APIs).

  7. Avoid definite assignment assertion operators on class methods

    main

    In TypeScript, while class fields can use the ! definite assignment assertion operator, class methods cannot. esbuild (v0.17.5+) now correctly enforces this restriction and will reject invalid syntax like y!() {}.

    class Foo {
      // Valid
      a?
      b!
      x?() {}
    
      // Invalid: will be rejected by esbuild
      y!() {}
    }
  8. CommonJS default imports in Babel mode

    main

    In version 0.14.27, esbuild changed how it handles default imports for CommonJS files when using Babel mode.

    • Node mode: The default import is always set to module.exports.
    • Babel mode: The default import passes through to module.exports.default.

    Previously, esbuild always created a forwarding default import in Babel mode even if module.exports.default did not exist. This could interfere with code iterating over the imported namespace object. Now, the default getter is only added in Babel mode if the default property actually exists on module.exports at the time of import.

  9. How ESM `require()` and `import()` behavior changed in v0.11.0

    main

    In v0.11.0, the way esbuild handles require() and import() of ESM files changed to improve performance and fix bugs related to entry point exports.

    Previous Behavior: Calling require() on an ESM file (or import() with code splitting disabled) converted the ESM file to CommonJS. This often resulted in exports being trapped inside a lazy-initialized closure, making them inaccessible to ESM-style export {} clauses.

    New Behavior: esbuild now uses lazy initialization instead of full CommonJS conversion. Variables are pulled out of the closure and are accessible to the rest of the module's scope.

    Key Implications:

    • Performance: ESM imports can now reference exports directly without the overhead of dynamic property access used in CommonJS-style exports.
    • Top-level Await: import() of a module with top-level await is now allowed even when code splitting is disabled, because the lazy initializer can now be async.
    • Correctness: Calling require() on an ESM file now recursively wraps all transitive dependencies to ensure correct runtime evaluation order. This increases code size but ensures correctness.
    • Recommendation: If you want to avoid the increased code size from recursive wrapping, use import statements instead of require() calls.
    // cjs-file.js
    console.log(require('./esm-file.js').foo)
    
    // esm-file.js
    export let foo = bar()