Registry / devops / babel-plugin-remove-template-literals-whitespace

babel-plugin-remove-template-literals-whitespace

JSON →
library1.0.4jsnpmunverified

Babel plugin that strips leading/trailing whitespace and indentation whitespace from template literals at build time. Latest version 1.0.4 is stable, with infrequent releases. Key features: customizable whitespace removal via user-defined function, optional verbose logging. Differentiators: lightweight, focused solely on template literal whitespace, works with any Babel setup. Alternatives like babel-plugin-transform-template-literals or manual post-processing are heavier or require additional configuration. Suitable for minifying HTML templates or CSS-in-JS strings.

npm install babel-plugin-remove-template-literals-whitespace
INSTALL
IMPORT
SIG · BABEL-PLUGIN-REMOV
B
babel-plugin-remove-template-literals-whitespace
devopsjavascriptv1.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = require('babel-plugin-remove-template-literals-whitespace')
import plugin from 'babel-plugin-remove-template-literals-whitespace'
Package does not export ESM; use CommonJS require(). In .babelrc or babel.config.js, use require() or string reference.
babel plugin usage
plugins: ['remove-template-literals-whitespace']
plugins: ['babel-plugin-remove-template-literals-whitespace']
Babel automatically resolves 'babel-plugin-' prefix; both forms work, but shorter preferred.
options
plugins: [['remove-template-literals-whitespace', { fn: (s) => s.trim() }]]
plugins: [['remove-template-literals-whitespace', { trim: true }]]
Options object must use 'fn' key for custom function, not 'trim'. 'verbose' key enables logging.

Demonstrates Babel config with custom fn to aggressively remove leading/trailing whitespace and newlines from template literals.

// babel.config.js module.exports = { plugins: [ ['remove-template-literals-whitespace', { fn: (str) => str.replace(/^\s+|\s+$/gm, '').replace(/\n\s*/g, '') }] ] }; // input.js const html = ` <div> <p>Hello</p> </div> `; // output.js (after Babel transformation) const html = `<div><p>Hello</p></div>`;
Debug
Known issues
gotchaCustom function 'fn' receives the raw template literal string. It must handle all whitespace removal logic; no default removal is applied.
fix
Ensure your fn function removes all whitespace as needed, e.g., str.replace(/\s+/g, ' ')
affects: >=1.0.0
gotchaPlugin only processes template literals that are direct children of a node (e.g., variable init, return). It does not process template literals inside JSX or other expressions.
fix
If using inside JSX, consider a JSX-specific plugin or manually wrap the template literal in a tagged template.
affects: >=1.0.0
deprecatedNo deprecations recorded. Plugin is simple and stable.
affects: all
Errors
Common errors & fixes
Error: Plugin/Preset files are not allowed to export objects, only functions.
Using ES module import syntax in babel.config.js for this plugin (which is CJS-only).
fix
Use require('babel-plugin-remove-template-literals-whitespace') or string shorthand in plugins array.
TypeError: Cannot read properties of undefined (reading 'replace')
Custom 'fn' is not provided or returns undefined; plugin tries to call replace on result.
fix
Define fn as a function that returns a string. Example: (str) => str.trim()
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
babel-plugin-remove-template-literals-whitespace — npm install babel-plugin-remove-template-literals-whitespace · libregistry