Feature request: Evaluate code during build using a prebuild evaluation function from esbuild
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I have a feature request!
> Evaluate code during build using a prebuild evaluation function from esbuild
I would love a feature where I could import a special function from esbuild, say `prebuild`, and use it to perform custom build tasks, like [constant folding](https://en.wikipedia.org/wiki/Constant_folding), [loop optimization](https://en.wikipedia.org/wiki/Loop_optimization), string injection and [other optimizations](https://en.wikipedia.org/wiki/Optimizing_compiler).
The `prebuild` function would take in a function as the only argument, with some data about the current build. For example the version number from the projects package.json file.
The function provided to `prebuild` would run during build, with all the typescript intellisense one would expect, and maybe it must return a string, or at least something serializable.
```ts
import React from 'react'
import {prebuild} from 'esbuild'
export const MyComponent = () => {
return (
)
}
```
In the first version, the developer would be responsible for making sure the resulting code is valid.
Is this feature in the backlog for esbuild?
-----
PS: I am aware that string injection is part of esbuild, but I find that solution a bit outdated and messy. Feel free to disagree:)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.