evanw / evanw/esbuild

Can an esbuild plugin transform the results of other plugins?

Open
#2,885 1 comment 1 reaction 0 assignees View on GitHub
plugins
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I know that plugins can transform existing files, but can they transform the results of other plugins?

For example, let's say I'm using [esbuild-plugin-eval](https://github.com/jed/esbuild-plugin-eval) to evaluate a module before import, which lets me write code like this:

```js
import html from 'html.js?eval'
```

Now I want to write a `compress` plugin that compresses the results of this plugin, so that I can write code like this:

```js
import compressedHtml from 'html.js?eval&compress'
```

The problem is, unlike the `eval` plugin, the `compress` plugin won't operate on an existing file in the filesystem, but _instead_ (in this case) the results of the `eval` plugin. I'm not sure how to accomplish this; resolving the `compress` plugin back to the `file` namespace will allow the `eval` plugin to detect it, but I don't know how to hook in to its output, and the `onLoad` handler doesn't have access to its output either.

I'd love some direction here if I'm missing something.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with esbuild's plugin API documentation, especially the onResolve and onLoad hooks and the file namespace behavior. Determine whether one plugin can consume another plugin's generated output rather than a filesystem file; done means documenting a supported chaining mechanism or confirming that the API does not provide one.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.