Socket
Socket
Sign inDemoInstall

esbuild-wasm

Package Overview
Dependencies
0
Maintainers
1
Versions
459
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    esbuild-wasm

The cross-platform WebAssembly binary for esbuild, a JavaScript bundler.


Version published
Weekly downloads
2.9M
increased by0.12%
Maintainers
1
Install size
10.7 MB
Created
Weekly downloads
 

Package description

What is esbuild-wasm?

The esbuild-wasm package is a WebAssembly-based version of the esbuild bundler and minifier. It provides extremely fast build times and is designed to be used in environments where native binaries cannot be executed, such as in browsers or some serverless platforms. It supports transforming, bundling, and minifying JavaScript and TypeScript files.

What are esbuild-wasm's main functionalities?

Bundling JavaScript

This code initializes esbuild-wasm and bundles a JavaScript file, outputting a single bundled file. It demonstrates how to set up and execute a basic bundling process.

const esbuild = require('esbuild-wasm');
esbuild.initialize({ worker: true, wasmURL: '/path/to/esbuild.wasm' }).then(() => {
  esbuild.build({
    entryPoints: ['input.js'],
    bundle: true,
    outfile: 'output.js'
  }).catch(() => process.exit(1));
});

Minifying CSS

This example shows how to use esbuild-wasm to minify a CSS file. It sets up the esbuild environment and performs minification, outputting the minified CSS.

const esbuild = require('esbuild-wasm');
esbuild.initialize({ worker: true, wasmURL: '/path/to/esbuild.wasm' }).then(() => {
  esbuild.build({
    entryPoints: ['input.css'],
    minify: true,
    outfile: 'output.css'
  }).catch(() => process.exit(1));
});

Transpiling TypeScript

This code snippet demonstrates how to transpile TypeScript into JavaScript using esbuild-wasm. It includes setting up the environment, specifying the loader for TypeScript files, and bundling the output.

const esbuild = require('esbuild-wasm');
esbuild.initialize({ worker: true, wasmURL: '/path/to/esbuild.wasm' }).then(() => {
  esbuild.build({
    entryPoints: ['input.ts'],
    loader: { '.ts': 'ts' },
    outfile: 'output.js',
    bundle: true
  }).catch(() => process.exit(1));
});

Other packages similar to esbuild-wasm

Changelog

Source

0.18.2

  • Lower static blocks when static fields are lowered (#2800, #2950, #3025)

    This release fixes a bug where esbuild incorrectly did not lower static class blocks when static class fields needed to be lowered. For example, the following code should print 1 2 3 but previously printed 2 1 3 instead due to this bug:

    // Original code
    class Foo {
      static x = console.log(1)
      static { console.log(2) }
      static y = console.log(3)
    }
    
    // Old output (with --supported:class-static-field=false)
    class Foo {
      static {
        console.log(2);
      }
    }
    __publicField(Foo, "x", console.log(1));
    __publicField(Foo, "y", console.log(3));
    
    // New output (with --supported:class-static-field=false)
    class Foo {
    }
    __publicField(Foo, "x", console.log(1));
    console.log(2);
    __publicField(Foo, "y", console.log(3));
    
  • Use static blocks to implement --keep-names on classes (#2389)

    This change fixes a bug where the name property could previously be incorrect within a class static context when using --keep-names. The problem was that the name property was being initialized after static blocks were run instead of before. This has been fixed by moving the name property initializer into a static block at the top of the class body:

    // Original code
    if (typeof Foo === 'undefined') {
      let Foo = class {
        static test = this.name
      }
      console.log(Foo.test)
    }
    
    // Old output (with --keep-names)
    if (typeof Foo === "undefined") {
      let Foo2 = /* @__PURE__ */ __name(class {
        static test = this.name;
      }, "Foo");
      console.log(Foo2.test);
    }
    
    // New output (with --keep-names)
    if (typeof Foo === "undefined") {
      let Foo2 = class {
        static {
          __name(this, "Foo");
        }
        static test = this.name;
      };
      console.log(Foo2.test);
    }
    

    This change was somewhat involved, especially regarding what esbuild considers to be side-effect free. Some unused classes that weren't removed by tree shaking in previous versions of esbuild may now be tree-shaken. One example is classes with static private fields that are transformed by esbuild into code that doesn't use JavaScript's private field syntax. Previously esbuild's tree shaking analysis ran on the class after syntax lowering, but with this release it will run on the class before syntax lowering, meaning it should no longer be confused by class mutations resulting from automatically-generated syntax lowering code.

Readme

Source

esbuild

This is the cross-platform WebAssembly binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild and the JavaScript API documentation for details.

FAQs

Last updated on 13 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