https://github.com/henrhie/esbuild-plugin-babel-flow
https://github.com/henrhie/esbuild-plugin-babel-flow
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/henrhie/esbuild-plugin-babel-flow
- Owner: henrhie
- License: mit
- Created: 2022-02-28T22:07:45.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-01T15:49:55.000Z (over 3 years ago)
- Last Synced: 2025-01-10T00:14:42.637Z (5 months ago)
- Language: JavaScript
- Size: 97.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# esbuild-plugin-babel-flow
Esbuild plugin for transformation of code with [Flow](https://flow.org/) annotations
Esbuild plugins have limitations to allow developers to hook into every part of the bundling process. This is a deliberate attempt to prevent creating performance bottlenecks during bundling.
Thankfully, Babel, a javascript code transformer allows you to transform code during the code loading event of the esbuild bundling process.
esbuild-plugin-babel-flow under the hood uses babel's transform api and `@babel/preset-flow` to strip javascript code of flow annotations for safe execution in a javascript environment.## Install
```bash
npm install esbuild-plugin-babel-flow --save-dev
```
## Usage
`esbuild.config.js`
```js
esbuild
.build({
entryPoints: ['example.flow.js'],
write: true,
bundle: true,
outdir: 'dist',
plugins: [babelFlowPlugin()],
})
.catch(() => process.exit(1));
````example.flow.js`
```js
// @flowfunction foo(x: ?number): string {
if (x) {
return JSON.stringify(x);
}
return 'default string';
}foo(55);
````dist/example.flow.js`
```js
(() => {
// example.flow.js
function foo(x) {
if (x) {
return JSON.stringify(x);
}
return 'default string';
}
foo(55);
})();
````package.json`
```json
{
"type": "module",
"scripts": {
"start": "node esbuild.config.js"
}
}
```## License
[MIT](https://choosealicense.com/licenses/mit/)