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-dynamic-sass-themes

v1.0.5

Published

A Vite plugin for dynamically compiling and applying SASS themes in your Vite project. This plugin allows you to manage multiple SASS themes, compile them on-the-fly, and dynamically update the styles in the browser without a full page reload.

Readme

vite-plugin-dynamic-sass-themes

A Vite plugin for dynamically compiling and applying SASS themes in your Vite project. This plugin allows you to manage multiple SASS themes, compile them on-the-fly, and dynamically update the styles in the browser without a full page reload.


Features

  • Dynamic Theme Compilation: Automatically compiles SASS themes from a specified directory.
  • Hot Module Replacement (HMR): Updates styles in the browser without reloading the page.
  • Customizable Options: Configure themes directory, output directory, logging, and SASS options.
  • TypeScript Support: Includes TypeScript declarations for the virtual module.

Installation

Install the plugin using npm, pnpm, or yarn:

# npm
npm install vite-plugin-dynamic-sass-themes --save-dev

# pnpm
pnpm add vite-plugin-dynamic-sass-themes --save-dev

# yarn
yarn add vite-plugin-dynamic-sass-themes --dev

Usage

1. Add the Plugin to vite.config.ts

Configure the plugin in your vite.config.ts file:

import { defineConfig } from "vite";
import dynamicSassThemePlugin from "vite-plugin-dynamic-sass-themes";

export default defineConfig({
  plugins: [
    dynamicSassThemePlugin({
      themesDir: "src/themes", // Relative path to themes directory
      outputDir: "public/themes", // Relative path to output directory
      log: true, // Enable logging
      sassOptions: {
        style: "compressed", // Minify CSS output
        sourceMap: true, // Generate source maps
      },
    }),
  ],
});

2. Import the Client-Side Code

In your main entry file (e.g., main.ts or main.js), import the client-side code:

import "virtual:dynamic-sass-themes-client";

3. Declare the Virtual Module in vite-env.d.ts

If you don’t already have a vite-env.d.ts file, create one in the root of your project. Then, add the following declaration for the virtual module:

/// <reference types="vite/client" />

// Declare the virtual module
declare module "virtual:dynamic-sass-themes-client" {
  const clientCode: string;
  export default clientCode;
}

4. Ensure vite-env.d.ts is Included in tsconfig.json

Make sure your tsconfig.json includes the vite-env.d.ts file:

{
  "compilerOptions": {
    "types": ["vite/client"]
  },
  "include": ["src", "vite-env.d.ts"]
}

Example Project Structure

Here’s how your project structure should look:

my-project/
├── src/
│   ├── main.ts
│   └── themes/
│       ├── light/
│       │   └── theme.scss
│       └── dark/
│           └── theme.scss
├── vite-env.d.ts
├── vite.config.ts
├── tsconfig.json
├── package.json
└── ...

How It Works

Plugin Side

  • The plugin watches for changes to .scss files in the themesDir.
  • When a .scss file changes, it compiles the file and sends the compiled CSS to the client via a custom HMR event (vite-plugin-dynamic-sass-themes:update).

Client Side

  • The client-side code is injected as a virtual module (virtual:dynamic-sass-themes-client).
  • When the HMR event is received, the client-side code dynamically updates the <style> element with the new CSS.

Testing

  1. Add the declaration to vite-env.d.ts in your project.
  2. Ensure vite-env.d.ts is included in tsconfig.json.
  3. Run your Vite development server.
  4. Modify a .scss file in your themesDir.
  5. Observe that the browser updates the styles dynamically without reloading the page, and TypeScript no longer throws an error.

Options

The plugin accepts the following options:

| Option | Type | Default | Description | | ------------- | ------- | ----------------- | ----------------------------------------------------- | | themesDir | string | "src/themes" | Directory containing theme SASS files. | | outputDir | string | "public/themes" | Output directory for compiled CSS. | | log | boolean | true | Enable/disable logging. | | sassOptions | object | {} | Additional SASS options (e.g., style, sourceMap). |


Contributing

If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Happy theming! 🎨