esbuild-plugin-pipe
Pipe esbuild plugins output.
A pipe is a form of redirection that is used to send the output of one program to another program for further processing.
⚠️ The plugins have to support piping.
Install
npm install esbuild-plugin-pipe --save-dev
Use
esbuild.config.js
import esbuild from 'esbuild';
import pipe from 'esbuild-plugin-pipe';
esbuild
.build({
entryPoints: ['index.js'],
bundle: true,
outfile: 'main.js',
plugins: [
pipe({
plugins: [...]
})
]
})
.catch(() => process.exit(1));
package.json
{
"type": "module",
"scripts": {
"start": "node esbuild.config.js"
}
}
Configure
esbuild.config.js
pipe({
filter: /.*/,
namespace: '',
plugins: []
});
Support
If you are a plugin maker, it's really easy to support piping. Here’s a commented plugin example.
const pluginExample = () => ({
name: 'example',
setup(build, { transform } = {}) {
const transformContents = ({ args, contents }) => {
return { contents };
};
if (transform) return transformContents(transform);
build.onLoad({ filter: /.*/ }, async args => {
const contents = await fs.promises.readFile(args.path, 'utf8');
return transformContents({ args, contents });
});
}
});
export default pluginExample;
Check
esbuild-plugin-babel → Babel plugin for esbuild.
esbuild-plugin-postcss-literal → PostCSS tagged template literals plugin for esbuild.