Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-plugin-pipe

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-plugin-pipe

Pipe esbuild plugins output.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by500%
Maintainers
1
Weekly downloads
 
Created
Source

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 } = {}) {
        // The `setup` function receives a new `transform` argument if it’s in a pipe.

        // Create a function and move all the content of your `onLoad` function in it, except the `readfile`.
        const transformContents = ({ args, contents }) => {
            // It receives an object as an argument containing both the standard arguments of the `onLoad` function
            // and the `contents` of the previous plugin or file.

            // Move your code here. It should return `contents`.
            return { contents };
        };

        // If the `transform` argument exists, pass it to your new function.
        if (transform) return transformContents(transform);

        // Else call your `onLoad` function.
        build.onLoad({ filter: /.*/ }, async args => {
            // Read the files from disk.
            const contents = await fs.promises.readFile(args.path, 'utf8');

            // Call your function, but this time pass an object with the `onLoad` arguments and the file `contents`.
            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.


Keywords

FAQs

Package last updated on 26 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc