esbuild-preserve-whitespace
v1.1.1
Published
Esbuild plugin for TypeScript transpilation with whitespace preservation
Downloads
36
Maintainers
Readme
esbuild-preserve-whitespace
An esbuild plugin that preserves blank lines and whitespace during TypeScript transpilation by temporarily marking them with special comments that esbuild preserves.
Installation
npm install -D esbuild-preserve-whitespaceyarn add -D esbuild-preserve-whitespacepnpm add -D esbuild-preserve-whitespacebun add -D esbuild-preserve-whitespaceUsage
Add the plugin to your esbuild configuration. Important: You must set legalComments: "inline" in your esbuild options for this plugin to work.
Basic Usage
import { esbuildPreserveWhitespacePlugin } from "esbuild-preserve-whitespace";
await esbuild.build({
// ... other esbuild options ...
legalComments: "inline", // Required!
plugins: [esbuildPreserveWhitespacePlugin()],
});With Options
import { esbuildPreserveWhitespacePlugin } from "esbuild-preserve-whitespace";
await esbuild.build({
// ... other esbuild options ...
legalComments: "inline",
plugins: [
esbuildPreserveWhitespacePlugin({
verbose: true, // Enable verbose logging
}),
],
});Options
| Option | Type | Default | Description |
|---------|-----------|---------|------------------------------|
| verbose | boolean | false | Enable verbose build logging |
How It Works
- Before build: Scans TypeScript files and temporarily replaces blank lines with special marker comments (
//! _BLANK_LINE_) - During build: esbuild processes the files, preserving the marker comments since
legalComments: "inline"is set - After build: Removes marker comments from output files and restores original source files
This approach ensures that blank lines are preserved in the final JavaScript output while maintaining clean source files.
Requirements
legalComments: "inline"must be set in your esbuild configuration
