New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

astro-remove-whitespace

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astro-remove-whitespace

Astro integration that removes whitespace between HTML tags in build output

1.0.0
Source
npm
Version published
Weekly downloads
2
-66.67%
Maintainers
0
Weekly downloads
 
Created
Source

Astro Remove Whitespace Plugin

A simple Astro Plugin that removes unnecessary whitespace between HTML tags in your build output.

Background

Originally created by Utsubo, a creative studio based in Japan, to optimize their web projects. We noticed that Astro's build process preserved whitespace between closing tags, which added unnecessary bytes to the final bundle. This plugin solves that issue by cleaning up the HTML output post-build.

Features

  • Removes whitespace between HTML tags in build output
  • Preserves source code readability
  • Runs automatically after build completion
  • Minimal configuration required
  • Maintains other spacing and formatting
  • Processes all HTML files in build directory recursively

Installation

npm install astro-remove-whitespace

Usage

Add the plugin to your astro.config.mjs:

import removeTagWhitespace from 'astro-remove-whitespace';

export default defineConfig({
  integrations: [
    removeTagWhitespace()
  ],
});

Before and After

Before:

</g> </g> </svg> </div> </button>

After:

</g></g></svg></div></button>

How It Works

The plugin hooks into Astro's build process using the astro:build:done hook. After the build is complete, it:

  • Recursively finds all HTML files in your build directory
  • Removes whitespace between closing tags using regex
  • Preserves other formatting and spacing
  • Writes the optimized content back to the files

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details

Credits

Created and maintained by Utsubo - A Technology-First creative studio.

Keywords

astro-integration

FAQs

Package last updated on 30 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts