Skip to content

Commit

Permalink
fix: generate pino files reference at runtime but not build time (#12)
Browse files Browse the repository at this point in the history
* fix: generate pino files reference at runtime but not build time

* docs: add Deploy to production section
  • Loading branch information
wd-David authored Jul 3, 2022
1 parent b72143d commit 118b7c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ build({
}).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

- Reference: [Pino Bundling](https://github.com/pinojs/pino/blob/master/docs/bundling.md)
Expand Down
11 changes: 4 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,14 @@ export default function esbuildPluginPino({

const contents = await readFile(args.path, 'utf8')

const absoluteOutputPath = path
.join(
path.resolve(process.cwd()),
currentBuild.initialOptions.outdir || 'dist'
)
.replace(/\\/g, '/')
const absoluteOutputPath = `\${process.cwd()}\${require('path').sep}${
currentBuild.initialOptions.outdir || 'dist'
}`

const functionDeclaration = `
function pinoBundlerAbsolutePath(p) {
try {
return require('path').join('${absoluteOutputPath}', p)
return require('path').join(\`${absoluteOutputPath}\`.replace(/\\\\/g, '/'), p)
} catch(e) {
const f = new Function('p', 'return new URL(p, import.meta.url).pathname');
return f(p)
Expand Down

0 comments on commit 118b7c3

Please sign in to comment.