astro-strip-whitespace
v0.2.1
Published
Astro integration that strips inter-node whitespace in Astro and Svelte templates.
Maintainers
Readme
astro-strip-whitespace
Astro integration that strips inter-node whitespace in .astro and .svelte templates before compilation.
Under the hood, this prepends the Vite plugin from unplugin-strip-whitespace in astro:config:done so it runs early.
Install
astro add astro-strip-whitespace
# or: pnpm add -D astro-strip-whitespace
# or: npm i -D astro-strip-whitespace
# or: yarn add -D astro-strip-whitespaceUsage
In astro.config.mjs / astro.config.ts:
import { defineConfig } from "astro/config";
import stripWhitespace from "astro-strip-whitespace";
export default defineConfig({
integrations: [stripWhitespace()],
});Options
The integration accepts the same options as unplugin-strip-whitespace (StripWhitespaceOptions). Common ones:
preserveBlankLines: keep "section breaks" by skipping gaps that contain an empty line.selectLanguage: restrict processing to only Astro or only Svelte.skipOnError: skip transform on errors instead of failing the build.
Example: only process Astro files
stripWhitespace({
selectLanguage: ["astro"],
});Notes
- If you also use Svelte via
@astrojs/svelte, the integration can strip whitespace in.sveltefiles too (default behavior). - This runs as a
pretransform to avoid hydration mismatches that can happen when whitespace is removed only in the final HTML.
License
MIT
