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

vite-plugin-css-sourcemap

v1.0.2

Published

A Vite plugin to generate CSS sourcemaps

Downloads

784

Readme

vite-plugin-css-sourcemap

A Vite plugin for handling CSS sourcemaps. This plugin ensures that CSS sourcemaps are properly generated and referenced in your Vite builds.

[!IMPORTANT] This plugin is only meant for the build phase, to generate sourcemap files for your build. It doesn't work on dev mode.

Features

  • Automatically generates sourcemaps for CSS files
  • Supports custom sourcemap file locations
  • Configurable sourcemap URL generation
  • Works with Vite's build process
  • Compatible with Vite 5.x and 6.x

Installation

npm install vite-plugin-css-sourcemap --save-dev
# or
yarn add vite-plugin-css-sourcemap --dev
# or
pnpm add vite-plugin-css-sourcemap --save-dev

Usage

Add the plugin to your Vite configuration:

// vite.config.js
import { defineConfig } from 'vite';
import cssSourcemap from 'vite-plugin-css-sourcemap';

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

Configuration Options

The plugin accepts the following options:

cssSourcemap({
  // Enable/disable the plugin
  enabled: true,

  // Custom extensions to process (default: ['.css', '.scss'])
  extensions: ['.css', '.scss', '.less'],

  // Custom folder for sourcemap files
  folder: 'sourcemaps',

  // Custom function to generate sourcemap URLs
  getURL: (fileName) => `sourcemaps/${fileName}`,
});

Options

| Option | Type | Default | Description | | ------------ | ------------------------------ | ------------------------ | ------------------------------------------ | | enabled | boolean | true | Enable or disable the plugin | | extensions | string[] | ['.css', '.scss'] | File extensions to process | | folder | string | '' | Custom folder for sourcemap files | | getURL | (fileName: string) => string | (fileName) => fileName | Custom function to generate sourcemap URLs |

Examples

Basic Usage

// vite.config.js
import { defineConfig } from 'vite';
import cssSourcemap from 'vite-plugin-css-sourcemap';

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

Custom Sourcemap Location

// vite.config.js
import { defineConfig } from 'vite';
import cssSourcemap from 'vite-plugin-css-sourcemap';

export default defineConfig({
  plugins: [
    cssSourcemap({
      folder: 'sourcemaps',
    }),
  ],
});

Custom Sourcemap URL Generation

// vite.config.js
import { defineConfig } from 'vite';
import cssSourcemap from 'vite-plugin-css-sourcemap';

export default defineConfig({
  plugins: [
    cssSourcemap({
      getURL: (fileName) => `/assets/sourcemaps/${fileName}`,
    }),
  ],
});

Process Additional File Types

// vite.config.js
import { defineConfig } from 'vite';
import cssSourcemap from 'vite-plugin-css-sourcemap';

export default defineConfig({
  plugins: [
    cssSourcemap({
      extensions: ['.css', '.scss', '.less'],
    }),
  ],
});

How It Works

This plugin hooks into Vite's build process to:

  1. Intercept CSS file processing
  2. Generate sourcemaps for CSS files
  3. Emit the sourcemap files to the output directory
  4. Add sourcemap references to the CSS files

The plugin works by:

  1. Using the transform hook to process CSS files and generate sourcemaps
  2. Using the generateBundle hook to ensure sourcemaps are properly emitted
  3. It observes vite:css-post plugin, specifically the augmentChunkHash hook to obtain the future id of the file.
  4. Allows configuring the sourcemap URL based on the provided options

Compatibility

This plugin is compatible with:

  • Vite 5.x
  • Vite 6.x

License

MIT