From 955da39105fa28e9be2b7b957e8629afa89c0036 Mon Sep 17 00:00:00 2001 From: "keisuke.karino" Date: Wed, 10 Nov 2021 08:56:56 +0900 Subject: [PATCH 1/5] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 91fa4f9..0bdb3e2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ts-css-modules-vite-plugin", "version": "1.0.6", - "description": "", + "description": "Read the definition of'vite.config.ts' and resolve the CSS Modules type.", "main": "dist/index.js", "scripts": { "build": "tsc --project tsconfig.json", From c87c6b17c9e4b9bc7075f2760fbefa1a30559f14 Mon Sep 17 00:00:00 2001 From: "keisuke.karino" Date: Wed, 10 Nov 2021 08:57:06 +0900 Subject: [PATCH 2/5] Update README.md --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/README.md b/README.md index 72050db..1b4933e 100644 --- a/README.md +++ b/README.md @@ -1 +1,56 @@ +

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`. + +## Install + +```bash +npm i -D ts-css-modules-vite-plugin +``` + +## Add it to the `tsconfig.json` + +```json +{ + "compilerOptions": { + ... + "plugins": [{"name": "ts-css-modules-vite-plugin"}] + }, +} +``` + +## Resolve the `vite.config.ts` + +Resolve the `preprocessorOptions` setting within the plugin. + +```ts +import react from "@vitejs/plugin-react"; +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")}`, + }; + }, + }, + }, + }, +}); +``` From 314347c3d09d6deab3f15e59125237d422f6f855 Mon Sep 17 00:00:00 2001 From: "keisuke.karino" Date: Wed, 10 Nov 2021 09:02:10 +0900 Subject: [PATCH 3/5] Remove unnesesary codes --- example/src/App.tsx | 2 +- src/css.ts | 31 +++---------------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index d993dc5..4717721 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -18,7 +18,7 @@ export const App: VFC = (props) => { commonStyles.hoge )} > - vite-plugin-sass-dts-example + ts-css-modules-vite-plugin-example ); }; diff --git a/src/css.ts b/src/css.ts index 278effa..bc2ddf6 100644 --- a/src/css.ts +++ b/src/css.ts @@ -3,19 +3,12 @@ import type { ResolvedConfig } from "vite"; import { getPreprocessorOptions } from "./options"; import { AdditionalData, Log } from "./type"; -const SPLIT_STR = `/* vite-plugin-sass-dts */\n`; - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -let loadedSassPreprocessor: any; - export const parseCss = ( log: Log, file: string, fileName: string, config: ResolvedConfig ): string => { - // const sass = loadSassPreprocessor(config); - const options = getPreprocessorOptions(config); const resolveFn = config.createResolver({ extensions: [".scss", ".sass", ".css"], @@ -73,27 +66,9 @@ const getData = ( filename: string, additionalData?: AdditionalData ): string => { - if (!additionalData) return `\n${SPLIT_STR}${data}`; + if (!additionalData) return `\n${data}`; if (typeof additionalData === "function") { - return additionalData(`\n${SPLIT_STR}${data}`, filename); + return additionalData(`\n${data}`, filename); } - return `${additionalData}\n${SPLIT_STR}${data}`; + return `${additionalData}\n${data}`; }; - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -// const loadSassPreprocessor = (config: ResolvedConfig): any => { -// try { -// if (loadedSassPreprocessor) { -// return loadedSassPreprocessor; -// } -// const fallbackPaths = require.resolve.paths?.("sass") || []; -// const resolved = require.resolve("sass", { -// paths: [config.root, ...fallbackPaths], -// }); -// return (loadedSassPreprocessor = require(resolved)); -// } catch (e) { -// throw new Error( -// `Preprocessor dependency 'sass' not found. Did you install it?` -// ); -// } -// }; From 5bc4edc4a17324c457d6c46b9d1a1965c8dd4550 Mon Sep 17 00:00:00 2001 From: "keisuke.karino" Date: Wed, 10 Nov 2021 09:02:41 +0900 Subject: [PATCH 4/5] Enable husky --- package.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0bdb3e2..8f22935 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "type": "git", "url": "git+https://github.com/activeguild/ts-css-modules-vite-plugin.git" }, - "author": "", + "author": "j1ngzoue", "license": "MIT", "bugs": { "url": "https://github.com/activeguild/ts-css-modules-vite-plugin/issues" @@ -40,5 +40,11 @@ "postcss-js": "^3.0.3", "sass": "^1.43.4", "ts-node": "^10.4.0" + }, + "lint-staged": { + "*.{js,ts,jsx,tsx}": [ + "eslint . --fix", + "prettier . --write" + ] } } From 9c5efd715346f75104e3ab64d803b43296ae3483 Mon Sep 17 00:00:00 2001 From: "keisuke.karino" Date: Wed, 10 Nov 2021 09:03:57 +0900 Subject: [PATCH 5/5] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1b4933e..01305b4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ npm i -D ts-css-modules-vite-plugin Resolve the `preprocessorOptions` setting within the plugin. ```ts -import react from "@vitejs/plugin-react"; import path from "path"; import { defineConfig } from "vite";