All Projects → activeguild → vite-plugin-sass-dts

activeguild / vite-plugin-sass-dts

Licence: MIT License
This is a plugin that automatically creates a type file when using the CSS module type-safely.

Programming Languages

typescript
32286 projects
shell
77523 projects
CSS
56736 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language
SCSS
7915 projects

Projects that are alternatives of or similar to vite-plugin-sass-dts

vite-plugin-relay
A vite plugin for Relay
Stars: ✭ 44 (+120%)
Mutual labels:  vite
vite-react-ts-tailwind-firebase-starter
Starter using Vite + React + TypeScript + Tailwind CSS. And already set up Firebase(v9), Prettier and ESLint.
Stars: ✭ 108 (+440%)
Mutual labels:  vite
vue3.0-template-admin
本项目基于vue3+ElementPlus+Typescript+Vite搭建一套通用的后台管理模板;并基于常见业务场景,抽象出常见功能组件;包括动态菜单,菜单权限、登录、主题切换、国际化、个人中心、表单页、列表页、复制文本、二维码分享等等
Stars: ✭ 500 (+2400%)
Mutual labels:  vite
vitesse-nuxt-bridge
🏕 Vitesse experience for Nuxt 2 and Vue 2
Stars: ✭ 149 (+645%)
Mutual labels:  vite
vite-plugin-env-compatible
Environment Variables Compatible for vite(with vue-cli, create-react-app and so on)
Stars: ✭ 35 (+75%)
Mutual labels:  vite
electron-vite-template
👻 A fast Simple Vite 2, Vue 3 and Electron 13.x template.
Stars: ✭ 56 (+180%)
Mutual labels:  vite
vite-vue3-lowcode
vue3.x + vite2.x + vant + element-plus H5移动端低代码平台 lowcode 可视化拖拽 可视化编辑器 visual editor 类似易企秀的H5制作、建站工具、可视化搭建工具
Stars: ✭ 1,309 (+6445%)
Mutual labels:  vite
unplugin
Unified plugin system for Vite, Rollup, Webpack, and more
Stars: ✭ 998 (+4890%)
Mutual labels:  vite
react-antd-low-code
简易版 react 低代码平台
Stars: ✭ 45 (+125%)
Mutual labels:  vite
vue-3-stackter
A Vue3 starter project setup with Vite, Vue-meta, Router, Vuex, Eslint, Prettier, Tailwind CSS, and some custom preferences. Also, there is a TypeScript branch of this same setup.
Stars: ✭ 93 (+365%)
Mutual labels:  vite
vite-plugin-md
Markdown with Vue for Vite
Stars: ✭ 289 (+1345%)
Mutual labels:  vite
vue3-realworld-example-app
Explore the charm of Vue composition API! Vite?
Stars: ✭ 364 (+1720%)
Mutual labels:  vite
learn-wasm
🎲 Learning WebAssembly
Stars: ✭ 57 (+185%)
Mutual labels:  vite
peeky
A fast and fun test runner for Vite & Node 🐈️ Powered by Vite ⚡️
Stars: ✭ 611 (+2955%)
Mutual labels:  vite
theme-generator
CSS Color Theme Generator based on Numl.Design theme generator & HSLuv color space 🌈
Stars: ✭ 17 (-15%)
Mutual labels:  vite
vue3-demo
💡 vue3新特性示例: 响应式API、组合式API、TodoMVC
Stars: ✭ 114 (+470%)
Mutual labels:  vite
giraffe
📰 Free news, blogs or magazines application theme, built with Vite & Vuetify created by HeroUI.
Stars: ✭ 46 (+130%)
Mutual labels:  vite
vite-svg-loader
Vite 2.x plugin to load SVG files as Vue components
Stars: ✭ 124 (+520%)
Mutual labels:  vite
vitawind
Install and Setting Tailwindcss automatically for Vite
Stars: ✭ 46 (+130%)
Mutual labels:  vite
github-contribution-graph
Add beautiful GitHub contribution/commit graph to your profile README!
Stars: ✭ 37 (+85%)
Mutual labels:  vite

vite-plugin-sass-dts Welcome 😀

GitHub Actions status

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
allGenerate boolean Create all d.ts files of the css, sass, scss files included in the project at build time.
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.
global.generate boolean Outputs the common style set in additionalData of preprocessorOptions as a global type definition file.
global.outFile string Specify the file that outputs the global common style with an absolute path.Relative paths will be supported.

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({
      allGenerate: true,
      global: {
        generate: true,
        outFile: path.resolve(__dirname, './src/style.d.ts'),
      },
    }),
  ],
})
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;
  }
}

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

;[src / 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'
}
export default classNames
export type ClassNames = 'header-1' | 'active' | GlobalClassNames

The type definition is output to the output path of the common style specified in the option.

;[src / style.d.ts]

declare const classNames: {
  readonly row: 'row'
}
export default classNames
export type ClassNames = 'row'

Principles of conduct

Please see the principles of conduct when building a site.

License

This library is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].