An esbuild plugin that preserves blank lines and whitespace during TypeScript transpilation. Version 1.1.1 requires esbuild ^0.19.0 and the legalComments: 'inline' option. It works by replacing blank lines with marker comments before esbuild processes files, then removing them after. Unlike esbuild's default behavior (which strips most whitespace), this plugin provides configurable preservation of formatting, useful for debugging, code review, or when output readability matters. The plugin is lightweight, typed (TypeScript), and maintained on GitHub. It has no runtime dependencies beyond esbuild.
npm install esbuild-preserve-whitespaceNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic esbuild build with whitespace preservation plugin. Note that legalComments: 'inline' is mandatory.
Add 'legalComments: "inline"' to esbuild options. Without it, marker comments used to preserve whitespace are removed.
Ensure build process handles errors (e.g., try/catch) and consider using a clean working directory. The plugin restores files on success but not on failure.
No fix; this is by design. Plugin operates on esbuild's onLoad callback; other files are untouched.
Upgrade to v1.1.0 or later which includes improved error recovery.
Add 'legalComments: "inline"' to your esbuild configuration object.
Use 'import { esbuildPreserveWhitespacePlugin } from 'esbuild-preserve-whitespace'' or 'const { esbuildPreserveWhitespacePlugin } = await import('esbuild-preserve-whitespace')'.Run 'npm install -D esbuild-preserve-whitespace' or equivalent for your package manager.