Make pino-pretty a devDependency #3083
mplibunao
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Not sure whether to open a separate discussion or comment on existing discussions like #322. But since there's no single thread collecting possible improvements in terms of bundle size, I decided to just open a new discussion.
Issue
Currently,
pino-pretty
is used as a dependency instead of a devDependency and is used for both dev and production by default as seen hereI want to make a case that this is not a good default as pretty-printing adds overhead and is not useful in production since most of the time, logs are either sent to a dedicated logging service or written to a file. Pretty printing adds overhead without bringing any significant value. In fact, even the
pino-pretty
docs itself recommends against usingpino-pretty
in production as seen hereAside from the performance overhead, there is also the bundle size impact (although very minimal). Since it's included in the dependencies, it will always be included in the final bundle. For some teams that use docker, some use a strategy called multi-stage builds where:
This reduces the final size by a lot since a lot of build tools, cli, etc are usually pretty heavy. However, putting the package in dependencies instead of devDependencies prevents such optimization.
Proposed solution
Instead of always using the following as a default config for pino
Use NODE_ENV to determine whether to include pino-pretty. Here's an example of how I would do it
This way, we can safely move pino-pretty into devDdependencies which will shave a few kbs as well improve overall throughput of payload.
What if users want to use pino-pretty in prod
If users want to use pino-pretty in production, then they can 1.) Override the default config which is already possible today. 2.) Install
pino-pretty
as a dependency in their own project to make sure it gets included in prodSummary
I do hope you'll consider this idea as it improves perf, bundle size and still gives payload users the flexibility to add it their prod dependencies. The bundle-size improvements are by no means mind-blowing but as they say, "A journey of a thousand miles begins with a single step"
This solution will be good for everyone, especially end-users and I think the implementation is simple enough that this could be considered a very low-hanging fruit for better performance
Beta Was this translation helpful? Give feedback.
All reactions