Trim a Dotenv File Without Losing Quoted Lines
Admin ·
Before reducing a .env file, find out how your loader treats a hash in unquoted text. The same characters can begin a comment in one loader and belong to the value in another.
Compare two comment rules on the release sample
Choose Load release sample and Compress .env. With the whitespace rule, the result drops from 221 to 91 UTF-8 bytes. The unquoted value build#gray stays as written because the hash touches the preceding word.
Change Unquoted hash rule to Node.js and compress again. The output is 86 bytes. The PRIVATE_TAG value becomes build because an unquoted hash starts a comment under Node.js rules. The quoted banner keeps its hash in both runs.
| Value | Whitespace rule | Node.js rule |
|---|---|---|
| API_PORT | 00443 | 00443 |
| BANNER | Deploy #2 | Deploy #2 |
| PRIVATE_TAG | build#gray | build |
| EMPTY | Empty string | Empty string |
Open ENV Compressor and load the release sampleNode.js dotenv values, comments and parserDocker Compose env file syntax
Check the blank line inside NOTE
Open the downloaded compressed.env. The NOTE assignment still spans three physical lines. The blank middle line and the two spaces before second are part of its value. The blank line between assignments is gone.
For the Node.js result, parse the original and the download with util.parseEnv and compare their returned string maps. Use the actual destination loader for the other comment rule because loaders can also differ on quote and interpolation behavior.
Open ENV Compressor and load the release sampleNode.js dotenv values, comments and parserDocker Compose env file syntax
Resolve ambiguous empty assignments first
An empty assignment with only spaces after the equals sign can behave differently in some Node.js releases. If compression pauses on that line, write the intended empty string as KEY="" and check the source again. Use text without a leading byte-order mark in Node.js mode.
The download still carries deployment values. Use the preview locally and share a separate template if the receiving person needs only the keys.
Common questions
Does compression remove blank lines inside quoted values?
Blank lines between assignments are removed. Blank lines inside a quoted multiline value are preserved.
Can I use the whitespace option for a Docker Compose file?
Compose documents the whitespace-before-hash rule for unquoted values. Check its other dotenv behavior and validate the result in the Compose version you deploy.