Example usage
Closed this issue · 3 comments
Please could you provide a working example in the project repository of how to use this plugin?
Background:
So, I built my bundle with pino as:
esbuild --platform=node --target=node14 --bundle --sourcemap --outfile=dist/index.js src/index.ts
how do I integrate the plugin?
I took output of that generation and put it as input for this plugin:
// error TS1208: 'build.ts' cannot be compiled under '--isolatedModules'
// because it is considered a global script file.
//
// Add an import, export, or an empty 'export {}' statement to make it a module.
export {}
// Multiple entryPoints & pino transports
const { build } = require('esbuild');
const esbuildPluginPino = require('esbuild-plugin-pino');
build({
entryPoints: {
index2: './dist/index.js',
},
outdir: 'dist',
plugins: [esbuildPluginPino({ transports: ['pino-pretty', 'pino-sentry'] })],
})
.catch(() => process.exit(1));
but the generated files seem wrong, they require files. that don't exist:
➜ yarn build
yarn run v1.22.19
$ yarn clean && yarn esbuild && ts-node build.ts && yarn declaration && yarn copy-files
$ rm -rf ./dist
$ esbuild --platform=node --target=node14 --bundle --sourcemap --outfile=dist/index.js src/index.ts
dist/index.js 920.9kb
dist/index.js.map 1.6mb
$ tsc --project tsconfig.declaration.json
$ set -e; install -d dist/bin; cp -p bin/pretty.sh dist/bin; cp -p config.json dist
✨ Done in 3.01s.
logger (esbuild) [★⇡4] ➜ ls dist
bin/ config.json index.js.map pino-file.js pino-pretty.js pino-worker.js thread-stream-worker.js
build.d.ts index.js index2.js pino-pipeline-worker.js pino-sentry.js src/
➜ cat dist/pino-file.js
"use strict";
const pino = require("./pino");
const { once } = require("events");
module.exports = async function(opts = {}) {
const destOpts = Object.assign({}, opts, { dest: opts.destination || 1, sync: false });
delete destOpts.destination;
const destination = pino.destination(destOpts);
await once(destination, "ready");
return destination;
};
Please could you provide a working example in the project repository of how to use this plugin?
Background:
So, I built my bundle with pino as:
esbuild --platform=node --target=node14 --bundle --sourcemap --outfile=dist/index.js src/index.ts
Your build script should look like this (ref: https://esbuild.github.io/api/#build-api):
// Multiple entryPoints & pino transports
const { build } = require('esbuild')
const esbuildPluginPino = require('esbuild-plugin-pino')
build({
entryPoints: ['src/index.js'],
platform: 'node',
target: ['node14'],
bundle: true,
sourcemap: true,
outdir: 'dist',
plugins: [esbuildPluginPino({ transports: ['pino-pretty', 'pino-sentry'] })],
}).catch(() => process.exit(1))
alright thanks!
do you know if there's typescript ts.d support? currently I created extra tsconfig and run declarations only. that creates multiple .ts.d files based on original source files, but the index.ts.d could be also be aggregated to single file.
$ cat tsconfig.declaration.json
// https://stackoverflow.com/a/52341335/2314626
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"isolatedModules": false,
}
}
$ tsc --project tsconfig.declaration.json
Please refer to the esbuild build API about ts.d.
I don't have this requirement in my projects.