npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

merge-and-update-css-bundle

v0.0.7

Published

A plugin that merges multiple CSS files into a single bundle and automatically updates it in the background during watch mode.

Readme

CSS Module Merge Plugin

A plugin that automatically merges and deduplicates CSS module files in your build output directory. It provides atomic file updates and maintains a consistent stylesheet through symbolic links.

Purpose

This plugin solves several common problems when working with CSS modules in build systems:

  1. Automatically combines multiple .module.css files into a single output file
  2. Deduplicates CSS rules to prevent redundancy
  3. Provides atomic updates to prevent style flickering during rebuilds
  4. Maintains file system consistency using symlinks and backup files
  5. Handles concurrent file operations safely

Installation

npm install css-module-merge-plugin
# or
pnpm install css-module-merge-plugin
pnpm install

To build the project:

pnpm build

Built files will be output to the dist/ directory.

Prerequisites

  • Node.js
  • pnpm (Package Manager)

Testing

Test files are written with TypeScript and are located in the tests/ directory.

API

mergeCssPlugin(outputFile, outputDir, options)

Creates a new instance of the merge CSS plugin.

Parameters:

  • outputFile (string): The path where the final merged CSS file should be written
  • outputDir (string): The directory to scan for CSS module files
  • options (MergeCssPluginOptions): Configuration options
type MergeCssPluginOptions = {
  extensions?: string[];     // File extensions to process (default: ['.module.css'])
  deduplicate?: boolean;     // Whether to remove duplicate rules (default: true)
  verbose?: boolean;         // Enable detailed logging (default: true)
}

Usage Example:

import { mergeCssPlugin } from 'css-module-merge-plugin';

const plugin = mergeCssPlugin(
  'dist/styles.css',        // output file
  'dist',                   // directory to scan
  {
    verbose: true,          // enable logging
    deduplicate: true       // remove duplicates
  }
);

Plugin Methods

onSuccess()

Automatically triggered after a successful build. This method:

  • Scans the output directory for .module.css files
  • Merges all found CSS files
  • Deduplicates rules using postcss
  • Performs atomic updates of the output file

onClear()

Clears all merged styles. Useful for clean builds or resets.

dispose()

Cleanup method to properly close file handles and remove temporary files.

File Structure

The plugin maintains several files for atomic updates:

  • styles.css: Main symlink that applications should reference
  • .styles.shadow.css: Internal symlink for atomic updates
  • styles.temp.css and styles.backup.css: Alternating files for atomic writes

Features

  1. Atomic Updates: Uses a symlink-based system to prevent file corruption during updates
  2. Deduplication: Removes duplicate CSS rules using postcss
  3. Parallel Processing: Handles file operations in batches for better performance
  4. Error Recovery: Includes rollback mechanisms for failed operations
  5. Resource Cleanup: Properly handles file descriptors and cleanup on process exit

Example Integration

import { build } from 'your-build-system';
import { mergeCssPlugin } from 'css-module-merge-plugin';

build({
  plugins: [
    mergeCssPlugin('dist/styles.css', 'dist', {
      verbose: true,
      deduplicate: true
    })
  ]
});

Error Handling

The plugin includes comprehensive error handling and logging:

  • File system operation errors are caught and logged
  • Symlink verification ensures file system consistency
  • Atomic updates include rollback mechanisms
  • Resource cleanup on process termination

Limitations

  1. Requires file system support for symlinks
  • File system with symlink support:
    • Unix-based systems (Linux, macOS): Supported by default
    • Windows:
      • Requires Developer Mode OR
      • Administrative privileges OR
      • Node.js with --enable-symlinks flag
  1. Designed for .module.css files by default
  2. Requires write permissions in the output directory