Socket
Socket
Sign inDemoInstall

esbuild-register

Package Overview
Dependencies
26
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    esbuild-register

Transpile JSX, TypeScript and esnext features on the fly with esbuild


Version published
Weekly downloads
4M
increased by0.94%
Maintainers
1
Install size
226 kB
Created
Weekly downloads
 

Package description

What is esbuild-register?

The esbuild-register package allows you to transpile your code on the fly using esbuild. This is particularly useful for running TypeScript or modern JavaScript that uses JSX or other newer syntax without a separate build step. It hooks into Node.js's require in order to automatically compile files on-the-fly when they are required.

What are esbuild-register's main functionalities?

Transpile TypeScript on the fly

This feature allows you to automatically transpile TypeScript files when they are required in Node.js. This is particularly useful for development environments, where you want to avoid a separate build step for TypeScript.

require('esbuild-register/dist/node').register({
  loader: 'tsx'
});

require('./your-ts-file.ts');

Transpile modern JavaScript (ES6+) on the fly

With this feature, you can automatically transpile modern JavaScript files that use ES6+ features or JSX. This is useful for running modern JavaScript directly in Node.js without pre-compilation.

require('esbuild-register').register({
  loader: 'jsx'
});

require('./your-modern-js-file.js');

Other packages similar to esbuild-register

Readme

Source

esbuild-register

npm version npm downloads

Install

npm i esbuild esbuild-register -D
# Or Yarn
yarn add esbuild esbuild-register --dev
# Or pnpm
pnpm add esbuild esbuild-register -D

Usage

node -r esbuild-register file.ts

It will use jsxFactory, jsxFragmentFactory and target options from your tsconfig.json

Experimental loader support

When using in a project with type: "module" in package.json, you need the --loader flag to load TypeScript files:

node --loader esbuild-register/loader -r esbuild-register ./file.ts

Programmatic Usage

const { register } = require('esbuild-register/dist/node')

const { unregister } = register({
  // ...options
})

// Unregister the require hook if you don't need it anymore
unregister()

Sponsors

sponsors

License

MIT © EGOIST

FAQs

Last updated on 14 Sep 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