{"id":19152,"library":"babel-plugin-remove-template-literals-whitespace","title":"babel-plugin-remove-template-literals-whitespace","description":"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.","status":"active","version":"1.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/oliverfindl/babel-plugin-remove-template-literals-whitespace","tags":["javascript","babel","babel-plugin","template-literals","remove-whitespace","remove-template-literals-whitespace","babel-plugin-remove-template-literals-whitespace"],"install":[{"cmd":"npm install babel-plugin-remove-template-literals-whitespace","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-remove-template-literals-whitespace","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-remove-template-literals-whitespace","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package does not export ESM; use CommonJS require(). In .babelrc or babel.config.js, use require() or string reference.","wrong":"import plugin from 'babel-plugin-remove-template-literals-whitespace'","symbol":"default","correct":"module.exports = require('babel-plugin-remove-template-literals-whitespace')"},{"note":"Babel automatically resolves 'babel-plugin-' prefix; both forms work, but shorter preferred.","wrong":"plugins: ['babel-plugin-remove-template-literals-whitespace']","symbol":"babel plugin usage","correct":"plugins: ['remove-template-literals-whitespace']"},{"note":"Options object must use 'fn' key for custom function, not 'trim'. 'verbose' key enables logging.","wrong":"plugins: [['remove-template-literals-whitespace', { trim: true }]]","symbol":"options","correct":"plugins: [['remove-template-literals-whitespace', { fn: (s) => s.trim() }]]"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = {\n  plugins: [\n    ['remove-template-literals-whitespace', {\n      fn: (str) => str.replace(/^\\s+|\\s+$/gm, '').replace(/\\n\\s*/g, '')\n    }]\n  ]\n};\n\n// input.js\nconst html = `\n  <div>\n    <p>Hello</p>\n  </div>\n`;\n\n// output.js (after Babel transformation)\nconst html = `<div><p>Hello</p></div>`;","lang":"javascript","description":"Demonstrates Babel config with custom fn to aggressively remove leading/trailing whitespace and newlines from template literals."},"warnings":[{"fix":"Ensure your fn function removes all whitespace as needed, e.g., str.replace(/\\s+/g, ' ')","message":"Custom function 'fn' receives the raw template literal string. It must handle all whitespace removal logic; no default removal is applied.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If using inside JSX, consider a JSX-specific plugin or manually wrap the template literal in a tagged template.","message":"Plugin 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"","message":"No deprecations recorded. Plugin is simple and stable.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use require('babel-plugin-remove-template-literals-whitespace') or string shorthand in plugins array.","cause":"Using ES module import syntax in babel.config.js for this plugin (which is CJS-only).","error":"Error: Plugin/Preset files are not allowed to export objects, only functions."},{"fix":"Define fn as a function that returns a string. Example: (str) => str.trim()","cause":"Custom 'fn' is not provided or returns undefined; plugin tries to call replace on result.","error":"TypeError: Cannot read properties of undefined (reading 'replace')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}