Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@web/dev-server-esbuild

Package Overview
Dependencies
Maintainers
6
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web/dev-server-esbuild

Plugin for using esbuild in @web/dev-server

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-37.32%
Maintainers
6
Weekly downloads
 
Created
Source

Dev Server esbuild

esbuild plugin for @web/test-runner-server and es-dev-server.

esbuild is a blazing fast build tool, and can be used to transform TS and JSX to JS. It can also transform modern JS to older JS for older browsers.

Usage

Install the package:

npm i -D @web/dev-server-esbuild

Create a configuration file:

const { esbuildPlugin } = require('@web/dev-server-esbuild');

module.exports = {
  plugins: [esbuildPlugin({ ts: true })],
};

Configuration

We expose the following options for esbuild:

type Target = 'auto' | 'esnext' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020';
type Loader = 'js' | 'jsx' | 'ts' | 'tsx';

interface EsbuildPluginArgs {
  target?: Target;
  js?: boolean;
  jsx?: boolean;
  ts?: boolean;
  tsx?: boolean;
  jsxFactory?: string;
  jsxFragment?: string;
  loaders: Record<string, Loader>;
  define?: { [key: string]: string };
}

Target

The target option defines what version of javascript to compile down to. This is primary for supporting older browsers.

The default target is auto. If this is configured we look at the browser's user agent. If you're on the latest version of a browser that adopts modern javascript syntax at a reasonable pace, we skip any compilation work.

The current set of browsers are Chrome, Firefox and Edge. Otherwise we compile to es2017. Because esbuild is so fast, this is not noticeable.

You can override this behavior by setting the target option yourself. If it is set to esnext, we skip any compilation for js files.

Examples

Typescript:

Transform all .ts files to javascript:

esbuildPlugin({ ts: true });

JSX:

Transform all .jsx files to javascript:

esbuildPlugin({ jsx: true });

By default, jsx gets transformed to React.createElement calls. You can change this to the JSX style you are using.

For example when importing from preact like this:

import { h, Fragment } from 'preact';
esbuildPlugin({ jsx: true, jsxFactory: 'h', jsxFragment: 'Fragment' });

If you want to use jsx inside .js files you need to set up a custom loader:

esbuildPlugin({ loaders: { js: 'jsx' }, jsxFactory: 'h', jsxFragment: 'Fragment' });

TSX

Transform all .tsx files to javascript:

esbuildPlugin({ tsx: true });
esbuildPlugin({ tsx: true, jsxFactory: 'h', jsxFragment: 'Fragment' });

JS

Transform all JS to older versions of JS:

esbuildPlugin({ js: true, target: 'es2017' });

Transform TS, but don't transform any JS:

esbuildPlugin({ ts: true, target: 'exnest' });

Keywords

FAQs

Package last updated on 11 Aug 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc