DEV Community

Cover image for Resolve types using the typescript plugin for CSS modules available in vite
j1ngzoue
j1ngzoue

Posted on • Edited on

3 2

Resolve types using the typescript plugin for CSS modules available in vite

You can resolve the read type of preprocessorOptions set in thevite.config.ts file.
Click here for the package repository

Install



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


Enter fullscreen mode Exit fullscreen mode

Add it to the tsconfig.json



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


Enter fullscreen mode Exit fullscreen mode

Demo

Image description

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

    },
  },
});


Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay