Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/activeguild/typescript-plugin-css-modules-vite

Read the definition of vite.config.ts and resolve the CSS Modules type. Supports sass.
https://github.com/activeguild/typescript-plugin-css-modules-vite

cssmodules plugin typescript vite

Last synced: about 13 hours ago
JSON representation

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

Awesome Lists containing this project

README

        

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

```bash
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`

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

## Resolve the `vite.config.ts`

Resolve the `preprocessorOptions` setting within the plugin.

```ts
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.

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

Use the workspace version.
![γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ 2022-12-23 23 20 51](https://user-images.githubusercontent.com/39351982/209350906-4eaef407-6a69-49b0-99a7-43ccd46c449e.png)