2.1.1 • Published 3 months ago

esbuild-plugin-pino v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

esbuild-plugin-pino

NPM version npm bundle size CI Release license

An esbuild plugin to generate extra pino files for bundling

Installation

npm install esbuild-plugin-pino

Description

This plugin allows to use of pino v7 with esbuild generated bundle files.

Note that, due to pino architecture (based on Node.js' Worker Threads), it is not possible to make it work without generating extra files.

This means that when using this plugin the following list of files will be generated at the root of your dist folder:

  • thread-stream.js
  • pino-worker.js
  • pino-pipeline-worker.js
  • pino-file.js

A file for each transport you specify in the plugin constructor's transports option. (see below) Each of the additional file is a bundle and therefore does not contain any external dependency, but it is needed to use pino and it must be included in the deployment.

Usage

Simply include the plugin in your esbuild build script. Make sure you provide the plugin a list of all the pino transports you use via the transports option (pino/file is always included so no need to specify it).

// General usage
const { build } = require('esbuild')
const esbuildPluginPino = require('esbuild-plugin-pino')

build({
  entryPoints: ['src/index.ts'],
  outdir: 'dist',
  plugins: [esbuildPluginPino({ transports: ['pino-pretty'] })],
}).catch(() => process.exit(1))
// Multiple entryPoints & pino transports
const { build } = require('esbuild')
const esbuildPluginPino = require('esbuild-plugin-pino')

build({
  entryPoints: {
    first: './first.js',
    'abc/cde/second': './second.js'
  },
  outdir: 'dist',
  plugins: [esbuildPluginPino({ transports: ['pino-pretty', 'pino-loki'] })],
}).catch(() => process.exit(1))
// Start from esbuild@^0.17.1
// Multiple entryPoints in an array of object & pino transports
const { build } = require('esbuild')
const esbuildPluginPino = require('esbuild-plugin-pino')

build({
  entryPoints: [
    {
      in: './test/fixtures/first.js',
      out: 'first'
    },
    {
      in: './test/fixtures/second.js',
      out: 'abc/cde/second'
    }
  ],
  outdir: 'dist',
  plugins: [esbuildPluginPino({ transports: ['pino-pretty', 'pino-loki'] })],
}).catch(() => process.exit(1))

Deploy to production

If you use docker or severless function like AWS Lambda, make sure to use the same outdir in your production. Ex: If your outdir is set to dist in esbuild, you need to copy the whole dist but not extracting files into the docker image root folder.

Credits

2.1.1

3 months ago

2.1.0

6 months ago

2.0.2

7 months ago

2.0.1

9 months ago

2.0.0

1 year ago

1.3.0

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.6

2 years ago