Skip to content

Read the definition of vite.config.ts and resolve the CSS Modules type. Supports sass.

License

Notifications You must be signed in to change notification settings

activeguild/typescript-plugin-css-modules-vite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4f26bb0 Â· Jun 29, 2023

History

87 Commits
Dec 23, 2022
Nov 23, 2021
Dec 23, 2022
Dec 23, 2022
Nov 9, 2021
Nov 9, 2021
Nov 5, 2021
Nov 5, 2021
Nov 5, 2021
Nov 9, 2021
Nov 9, 2021
Nov 5, 2021
Nov 9, 2021
Nov 5, 2021
Dec 23, 2022
Jun 29, 2023
Jun 29, 2023
Nov 6, 2021

Repository files navigation

ts-css-modules-vite-plugin ⚡ Welcome 😀

GitHub Actions status

ts-css-modules-vite-plugin

Read the definition of vite.config.ts and resolve the CSS Modules type. Supports sass.

Demo

Install

npm i -D ts-css-modules-vite-plugin

Options

Parameter Type Description
root string Set the relative path from the project root to the 'vite.config.ts' file. (default ./)

Add it to the tsconfig.json

{
  "compilerOptions": {
    ...
    "plugins": [{"name": "ts-css-modules-vite-plugin", "root": "./"}]
  },
}

Resolve the vite.config.ts

Resolve the preprocessorOptions setting within the plugin.

import path from "path";
import { defineConfig } from "vite";

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")}`,
          };
        },
      },
    },
  },
});

Using VS Code

The VScode typescript version needs to match the project. Set the following.

{
  "typescript.tsdk": "node_modules/typescript/lib"
}

Use the workspace version. スクリーンショット 2022-12-23 23 20 51

About

Read the definition of vite.config.ts and resolve the CSS Modules type. Supports sass.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published