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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-css-module-types

v1.0.0

Published

Vite dev-server plugin that generates .d.ts declarations for CSS Modules

Readme

vite-plugin-css-module-types

Vite dev-server plugin that generates .d.ts declarations for CSS Modules. With css.devSourcemap enabled, includes JSDoc links to original CSS source lines and declaration maps for "Go to Definition".

Inspired by vite-plugin-css-module-dts and typed-css-modules.

Quick start

// vite.config.ts
import viteCssModuleTypesPlugin from 'vite-plugin-css-module-types';

export default defineConfig({
  css: { devSourcemap: true },
  plugins: [
    viteCssModuleTypesPlugin({
      dtsOutputDir: 'tmp/vite-plugin-css-module-types', // add to .gitignore
      include: ['apps/web/src'],
      exclude: ['apps/web/src/legacy'],
    }),
  ],
});

Add to your .gitignore:

tmp/vite-plugin-css-module-types/

Add to your tsconfig.json:

{
  "compilerOptions": {
    "rootDirs": [
      "./src",
      "./tmp/vite-plugin-css-module-types/src"
    ]
  },
  "include": [
    "**/*.ts",
    "**/*.tsx",
    "tmp/vite-plugin-css-module-types/src"
  ]
}

If you use /src in your rootDirs (as in the example above), it's best to also add the corresponding path from the output directory (e.g., ./tmp/vite-plugin-css-module-types/src) to avoid issues with path mapping.

Runs only in serve mode. Processes *.module.css files.

Options

| Option | Type | Default | Description | | -------------------------- | -------------------- | ----------- | -------------------------------------------------------------------- | | dtsOutputDir | string | — | Required. Output directory for .d.ts files, relative to root. | | include | string \| string[] | undefined | Folder(s) to include (prefix-matched). | | exclude | string \| string[] | undefined | Folder(s) to exclude. Wins when both match. | | namedExports | boolean | false | Emit export declare const per class. | | allowArbitraryExtensions | boolean | false | Use TS 5.0+ .d.module.css.ts naming instead of .module.css.d.ts. | | declarationMap | boolean | true | Generate .d.ts.map for "Go to Definition". Needs devSourcemap. |

Path matching is prefix-based (not glob). Separators are normalized, ./ and trailing / are stripped.

Output examples

Default mode

declare const styles: {
  /** [↗ button.module.css:3](file:///abs/path/button.module.css#L3) */
  readonly 'btn-primary': '_btn-primary_x1y2z';
};
export default styles;

With namedExports: true

/** [↗ button.module.css:3](file:///abs/path/button.module.css#L3) */
export declare const btnPrimary: string;

declare const styles: {
  readonly 'btn-primary': '_btn-primary_x1y2z';
  readonly btnPrimary: '_btn-primary_x1y2z';
};
export default styles;

With CSS docblock comments

/** Main call-to-action button. */
.btn-primary { color: blue; }
declare const styles: {
  /**
   * ```txt
   * Main call-to-action button.
   * ```
   * ---
   * ```css
   * .btn-primary { color: blue; }
   * ```
   * ---
   * [↗ button.module.css:2](file:///abs/path/button.module.css#L2)
   */
  readonly 'btn-primary': '_btn-primary_x1y2z';
};
export default styles;

Empty module

export {};

Dependencies