@toolsnap/css-minifier-tool
v1.0.0
Published
A lightweight CSS minifier and beautifier tool for optimizing and formatting CSS code
Downloads
16
Maintainers
Readme
@toolsnap/css-minifier-tool
A lightweight, zero-dependency CSS minifier and beautifier tool for optimizing and formatting CSS code in Node.js or the browser.
Features
- CSS Minification — Remove whitespace, comments, and unnecessary characters to reduce file size
- CSS Beautification — Format compressed CSS into readable, well-indented code
- Configurable Output — Control indentation, newline style, and comment preservation
- Zero Dependencies — Lightweight and fast with no external packages required
- Browser & Node.js — Works in both environments
Installation
npm install @toolsnap/css-minifier-toolUsage
Minify CSS
const { minify } = require('@toolsnap/css-minifier-tool');
const input = `
/* Header styles */
.header {
display: flex;
align-items: center;
background-color: #ffffff;
margin-bottom: 20px;
}
`;
const result = minify(input);
console.log(result);
// .header{display:flex;align-items:center;background-color:#fff;margin-bottom:20px}Beautify CSS
const { beautify } = require('@toolsnap/css-minifier-tool');
const compressed = '.header{display:flex;align-items:center;background-color:#fff}';
const formatted = beautify(compressed, { indent: 2 });
console.log(formatted);
// .header {
// display: flex;
// align-items: center;
// background-color: #fff;
// }Use Cases
- Production Builds — Minify CSS assets before deployment to reduce page load times
- Development — Beautify third-party CSS libraries for easier debugging and reading
- Build Pipelines — Integrate into Webpack, Gulp, or Rollup workflows
- CSS Analysis — Parse and reformat CSS for linting and code review
Best Practices
- Always keep original source files — Minify copies, not your source CSS
- Enable gzip/brotli compression — Minified CSS combined with server compression yields the best results
- Test before and after — Verify minified output renders identically to the original
- Use source maps in development — Map minified CSS back to original files for easier debugging
- Benchmark your CSS — Measure the actual size reduction to track optimization gains
License
MIT
Try our free online tools at RiseTop
