Socket
Socket
Sign inDemoInstall

esbuild

Package Overview
Dependencies
22
Maintainers
2
Versions
446
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    esbuild

An extremely fast JavaScript and CSS bundler and minifier.


Version published
Weekly downloads
25M
decreased by-9.19%
Maintainers
2
Install size
8.89 MB
Created
Weekly downloads
 

Package description

What is esbuild?

esbuild is a fast JavaScript bundler and minifier. It compiles TypeScript and JavaScript into a single file, minifies it, and can also handle CSS and image assets. It's designed for speed and efficiency, utilizing parallelism and native Go code to achieve its performance.

What are esbuild's main functionalities?

Bundling JavaScript

This code bundles 'app.js' and its dependencies into a single file 'out.js'.

require('esbuild').build({
  entryPoints: ['app.js'],
  bundle: true,
  outfile: 'out.js'
}).catch(() => process.exit(1))

Minifying JavaScript

This code minifies 'app.js' to reduce file size and improve load times.

require('esbuild').build({
  entryPoints: ['app.js'],
  minify: true,
  outfile: 'out.js'
}).catch(() => process.exit(1))

Transpiling TypeScript

This code compiles a TypeScript file 'app.ts' into JavaScript and bundles it into 'out.js'.

require('esbuild').build({
  entryPoints: ['app.ts'],
  bundle: true,
  outfile: 'out.js'
}).catch(() => process.exit(1))

Serving files for development

This code starts a local server to serve files from the 'public' directory and bundles 'app.js' into 'public/out.js'.

require('esbuild').serve({
  servedir: 'public',
  port: 8000
}, {
  entryPoints: ['app.js'],
  bundle: true,
  outfile: 'public/out.js'
}).then(server => {
  // Server started
})

Other packages similar to esbuild

Changelog

Source

0.18.7

  • Add support for using declarations in TypeScript 5.2+ (#3191)

    TypeScript 5.2 (due to be released in August of 2023) will introduce using declarations, which will allow you to automatically dispose of the declared resources when leaving the current scope. You can read the TypeScript PR for this feature for more information. This release of esbuild adds support for transforming this syntax to target environments without support for using declarations (which is currently all targets other than esnext). Here's an example (helper functions are omitted):

    // Original code
    class Foo {
      [Symbol.dispose]() {
        console.log('cleanup')
      }
    }
    using foo = new Foo;
    foo.bar();
    
    // New output (with --target=es6)
    var _stack = [];
    try {
      var Foo = class {
        [Symbol.dispose]() {
          console.log("cleanup");
        }
      };
      var foo = __using(_stack, new Foo());
      foo.bar();
    } catch (_) {
      var _error = _, _hasError = true;
    } finally {
      __callDispose(_stack, _error, _hasError);
    }
    

    The injected helper functions ensure that the method named Symbol.dispose is called on new Foo when control exits the scope. Note that as with all new JavaScript APIs, you'll need to polyfill Symbol.dispose if it's not present before you use it. This is not something that esbuild does for you because esbuild only handles syntax, not APIs. Polyfilling it can be done with something like this:

    Symbol.dispose ||= Symbol('Symbol.dispose')
    

    This feature also introduces await using declarations which are like using declarations but they call await on the disposal method (not on the initializer). Here's an example (helper functions are omitted):

    // Original code
    class Foo {
      async [Symbol.asyncDispose]() {
        await new Promise(done => {
          setTimeout(done, 1000)
        })
        console.log('cleanup')
      }
    }
    await using foo = new Foo;
    foo.bar();
    
    // New output (with --target=es2022)
    var _stack = [];
    try {
      var Foo = class {
        async [Symbol.asyncDispose]() {
          await new Promise((done) => {
            setTimeout(done, 1e3);
          });
          console.log("cleanup");
        }
      };
      var foo = __using(_stack, new Foo(), true);
      foo.bar();
    } catch (_) {
      var _error = _, _hasError = true;
    } finally {
      var _promise = __callDispose(_stack, _error, _hasError);
      _promise && await _promise;
    }
    

    The injected helper functions ensure that the method named Symbol.asyncDispose is called on new Foo when control exits the scope, and that the returned promise is awaited. Similarly to Symbol.dispose, you'll also need to polyfill Symbol.asyncDispose before you use it.

  • Add a --line-limit= flag to limit line length (#3170)

    Long lines are common in minified code. However, many tools and text editors can't handle long lines. This release introduces the --line-limit= flag to tell esbuild to wrap lines longer than the provided number of bytes. For example, --line-limit=80 tells esbuild to insert a newline soon after a given line reaches 80 bytes in length. This setting applies to both JavaScript and CSS, and works even when minification is disabled. Note that turning this setting on will make your files bigger, as the extra newlines take up additional space in the file (even after gzip compression).

Readme

Source

esbuild

This is a JavaScript bundler and minifier. See https://github.com/evanw/esbuild and the JavaScript API documentation for details.

FAQs

Last updated on 24 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc