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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-sass-dts-plus

v1.3.7

Published

A plugin that automatically creates a type file when using the css module type-safely.

Downloads

1

Readme

vite-plugin-sass-dts

A plugin that automatically creates a type file when using the CSS module type-safely.

Demo

Install

npm i -D vite-plugin-sass-dts

Options

| Parameter | Type | Description | | --------------------- | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | enabledMode | string[] | Create d.ts files for css modules of file extension css, sass, scss included in the project at build time.Valid enumerations 'development' and 'production'. By default it is enabled only for development.We recommend that you turn off the flag once you have created the d.ts file, as it will take a long time to build. (default [development]) | | global.generate | boolean | Outputs the common style set in additionalData of preprocessorOptions as a global type definition file. | | global.outputFilePath | string | Specify the file that outputs the global common style with an absolute path.Relative paths will be supported. | | typeName.replacement | string | (fileName: string) => string | Type name can be changed to any value. (default is the classname key as a string. e.g. theClassName: 'theClassName';) | | outputDir | string | An absolute path to the output directory. If undefined, declaration files will be generated in the source directories. ) | | sourceDir | string | An absolute path to your source code directory. The plugin will replace this path with outputDiroption when writing declaration files.) |

Add it to vite.config.ts

import { defineConfig } from 'vite'
import sassDts from 'vite-plugin-sass-dts'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [sassDts()],
})

Usage

You can create a dts file by saving the scss file during development. You can check the usage example when the following options are set. Prepare the vite.config.ts file with the following options and start it in development mode.

[vite.config.ts]

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import sassDts from 'vite-plugin-sass-dts'
import path from 'path'

export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/styles" as common;`,
        importer(...args) {
          if (args[0] !== '@/styles') {
            return
          }

          return {
            file: `${path.resolve(__dirname, './src/assets/styles')}`,
          }
        },
      },
    },
  },
  plugins: [
    react(),
    sassDts({
      enabledMode: ['development', 'production'],
      global: {
        generate: true,
        outputFilePath: path.resolve(__dirname, './src/style.d.ts'),
      },
      sourceDir: path.resolve(__dirname, './src'),
      outputDir: path.resolve(__dirname, './dist'),
    }),
  ],
})
npm run dev

Then save the following file ...

[src/assets/styles/_index.scss]

.row {
  display: flex;
}

[src/App.module.scss]

.header-1 {
  background-color: common.$primary;
  &.active {
    background-color: black;
  }
}

.input {
  @media (min-width: 768px) {
    max-width: 370px;
  }
}

Saving the scss file creates a d.ts file in the outputDir hierarchy.

Note: if outputDir is not set, declaration files are output to the same directory as the source files.

[dist/App.scss.d.ts]

import globalClassNames, { ClassNames as GlobalClassNames } from './style.d'
declare const classNames: typeof globalClassNames & {
  readonly 'header-1': 'header-1'
  readonly active: 'active'
  readonly input: 'input'
}
export = classNames

The optional global type definition is output to the output path of the common style specified in the options.

[src/style.d.ts]

declare const classNames: {
  readonly row: 'row'
}
export = classNames

Principles of conduct

Please see the principles of conduct when building a site.

License

This library is licensed under the MIT license.