esbuild-esm-loader

0.3.1 • Public • Published

ESBuild ESM Loader

ESBuild ESM Loader is a custom resolver implementation for the experimental module customization hooks feature of Node.js ECMAScript modules.

Using this loader will enhance the default loader behavior to allow you to transform imported files using ESBuild, allowing for transparent imports of modern JavaScript, JSX, and TypeScript.

// index.jsx
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';

console.log(renderToStaticMarkup(<div>Hello World!</div>));
node --import=esbuild-esm-loader/register ./index.jsx

Installation

The current version of the library requires Node.js v16.12 or newer.

Install as a dependency using npm. You will also need to install ESBuild, as it's a peer dependency of this project.

npm install esbuild esbuild-esm-loader

Usage

Loaders can be defined as an argument when running node.

node --import=esbuild-esm-loader/register entry.js

Configuration

If present, a tsconfig.json will be read and provided to ESBuild as the tsconfigRaw option. You can use this to control behavior such as JSX pragma with TypeScript's jsxFactory configuration option. This applies even if you are not using TypeScript.

Versioning

This project follows Semantic Versioning.

To better align with the experimental status of the loader hooks, initial releases will follow major version zero until the feature stabilizes in Node.js. Minor versions on the zero major will always include breaking changes. Patch versions on the zero major will include bug fixes and backwards-compatible changes.

Versioning will proceed from 1.0.0 once the feature stabilizes in Node.js.

License

Copyright 2024 Andrew Duthie

Released under the MIT License. See LICENSE.md.

Readme

Keywords

Package Sidebar

Install

npm i esbuild-esm-loader

Weekly Downloads

343

Version

0.3.1

License

MIT

Unpacked Size

8.79 kB

Total Files

5

Last publish

Collaborators

  • aduth