Read the definition of vite.config.ts and resolve the CSS Modules type.
Supports sass.
npm i -D ts-css-modules-vite-plugin| Parameter | Type | Description |
|---|---|---|
| root | string | Set the relative path from the project root to the 'vite.config.ts' file. (default ./) |
{
"compilerOptions": {
...
"plugins": [{"name": "ts-css-modules-vite-plugin", "root": "./"}]
},
}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")}`,
};
},
},
},
},
});The VScode typescript version needs to match the project. Set the following.
{
"typescript.tsdk": "node_modules/typescript/lib"
}
