unplugin-strip-whitespace

Unplugin to strip inter-node whitespace in Astro and Svelte templates (Vite/Rollup/Webpack/Rspack/etc).
787
Install
npm install unplugin-strip-whitespace
Latest Version:0.2.2
Vue:3
License:MIT
Last Updated:Mar 28, 2026
Links: GitHub  ·  npm
Maintainer: segararai

unplugin-strip-whitespace

Strip inter-node whitespace in .astro and .svelte templates before they’re compiled.

This package is an unplugin plugin, so it works with Vite, Rollup, Webpack, Rspack, esbuild, Farm, Nuxt, and more.

If you’re using Astro, you may prefer the dedicated integration: astro-strip-whitespace.

Install

pnpm add -D unplugin-strip-whitespace
# npm i -D unplugin-strip-whitespace
# yarn add -D unplugin-strip-whitespace

Usage

Vite

// vite.config.ts
import { defineConfig } from "vite";
import stripWhitespace from "unplugin-strip-whitespace/vite";

export default defineConfig({
  plugins: [stripWhitespace()],
});

Rollup

// rollup.config.ts
import stripWhitespace from "unplugin-strip-whitespace/rollup";

export default {
  plugins: [stripWhitespace()],
};

Webpack

// webpack.config.js
const stripWhitespace = require("unplugin-strip-whitespace/webpack");

module.exports = {
  plugins: [stripWhitespace.default()],
};

Rspack

// rspack.config.ts
import stripWhitespace from "unplugin-strip-whitespace/rspack";

export default {
  plugins: [stripWhitespace()],
};

esbuild

import stripWhitespace from "unplugin-strip-whitespace/esbuild";

// ...
plugins: [stripWhitespace()],

Nuxt

This package also ships a small Nuxt module.

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ["unplugin-strip-whitespace/nuxt"],
  unpluginStripWhitespace: {
    preserveBlankLines: true,
  },
});

Options

All options are optional.

import type { StripWhitespaceOptions } from "unplugin-strip-whitespace";
  • selectLanguage: ("astro" | "svelte")[] or (id, content) => "astro" | "svelte" | false
    • Default behavior processes .astro and .svelte files, skipping node_modules and any id containing a query string (?).
  • preserveBlankLines: boolean or (lang, id, content) => boolean
    • When true, skips stripping for gaps that contain an empty line (useful as a “section break” marker).
  • movePluginBefore: RegExp | (name) => boolean | false | { vite?: …; rollup?: …; ... }
    • Attempts to move this plugin earlier in the final plugin list (where supported).
    • Default: /^astro:build|^vite-plugin-svelte$/.
  • skipOnError: boolean
    • When true, errors are logged as warnings and the transform is skipped.

Example:

stripWhitespace({
  preserveBlankLines: true,
  movePluginBefore: {
    vite: /^astro:build|^vite-plugin-svelte$/,
  },
});

What it strips (and why)

This removes whitespace-only gaps between nodes in templates. It’s designed to be safe for hydration by running before Astro/Svelte compilation, rather than minifying the final HTML output.

License

MIT

Related Packages

unplugin-kubb

Integration of Kubb for Vite, webpack, Rollup, Rolldown, Rspack, esbuild, Farm,...

328,886 1,825
@relevate/unplugin-poolster

Run Poolster OpenAPI generation from Vite, Rollup, webpack, esbuild, Rspack, Rol...

197 3
unplugin-lightningcss

Lightning CSS integration for Vite, Rollup, esbuild, Webpack, Vue CLI, and more.

1,880,181 29
@styleframe/plugin

Unplugin for Styleframe. Use it with Vite, Webpack, Astro, Nuxt, Rollup, Rspack,...

24,920 91

Version History

Version Released Vue License
0.2.2 ^3.0 MIT
0.2.1 ^3.0 MIT
0.2.0 ^3.0 MIT