Socket
Socket
Sign inDemoInstall

esbuild-wasm

Package Overview
Dependencies
0
Maintainers
1
Versions
461
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.32%
Maintainers
1
Install size
10.2 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.17.7

  • Change esbuild's parsing of TypeScript instantiation expressions to match TypeScript 4.8+ (#2907)

    This release updates esbuild's implementation of instantiation expression erasure to match microsoft/TypeScript#49353. The new rules are as follows (copied from TypeScript's PR description):

    When a potential type argument list is followed by

    • a line break,
    • an ( token,
    • a template literal string, or
    • any token except < or > that isn't the start of an expression,

    we consider that construct to be a type argument list. Otherwise we consider the construct to be a < relational expression followed by a > relational expression.

  • Ignore sideEffects: false for imported CSS files (#1370, #1458, #2905)

    This release ignores the sideEffects annotation in package.json for CSS files that are imported into JS files using esbuild's css loader. This means that these CSS files are no longer be tree-shaken.

    Importing CSS into JS causes esbuild to automatically create a CSS entry point next to the JS entry point containing the bundled CSS. Previously packages that specified some form of "sideEffects": false could potentially cause esbuild to consider one or more of the JS files on the import path to the CSS file to be side-effect free, which would result in esbuild removing that CSS file from the bundle. This was problematic because the removal of that CSS is outwardly observable, since all CSS is global, so it was incorrect for previous versions of esbuild to tree-shake CSS files imported into JS files.

  • Add constant folding for certain additional equality cases (#2394, #2895)

    This release adds constant folding for expressions similar to the following:

    // Original input
    console.log(
      null === 'foo',
      null === undefined,
      null == undefined,
      false === 0,
      false == 0,
      1 === true,
      1 == true,
    )
    
    // Old output
    console.log(
      null === "foo",
      null === void 0,
      null == void 0,
      false === 0,
      false == 0,
      1 === true,
      1 == true
    );
    
    // New output
    console.log(
      false,
      false,
      true,
      false,
      true,
      false,
      true
    );
    

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 09 Feb 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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc