@almighty-shogun/vite-preset 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CODEOWNERS +1 -0
- package/LICENSE +21 -0
- package/README.md +9 -2
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -5
- package/src/cssModules.ts +56 -0
- package/src/deps.d.ts +3 -0
- package/src/index.ts +3 -0
package/CODEOWNERS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @Almighty-Shogun
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 - 2026 Almighty-Shogun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vite Preset
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CSS Modules class name generation for Vite projects.
|
|
4
|
+
|
|
5
|
+
## 📃 Prerequisites
|
|
6
|
+
- **[Bun](https://bun.sh)**: >= 1.3.10
|
|
7
|
+
|
|
8
|
+
## 📦 Building
|
|
9
|
+
- Use the command `bun install` in the root directory to install the required dependencies.
|
|
10
|
+
- Run `bun --cwd packages/vite-preset build` to build the package.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
//#region src/cssModules.d.ts
|
|
3
|
+
type Options = {
|
|
4
|
+
readonly classNames?: 'mangled' | 'camel' | 'kebab';
|
|
5
|
+
readonly generateScopeName?: (name: string, filename: string, css: string) => string;
|
|
6
|
+
readonly prefix?: string;
|
|
7
|
+
};
|
|
8
|
+
declare const cssModules: (options?: Options) => Plugin[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { cssModules };
|
|
11
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/cssModules.ts"],"mappings":";;KAKK;WACQ;WACA,qBAAqB,cAAc,kBAAkB;WACrD;;cAGP,aAAc,UAAS,YAAe"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"css-class-generator";import{camelCase as t,kebabCase as n}from"change-case";import{patchCssModules as r}from"vite-css-modules";const i=(i={})=>{let a=[];function o(r){r.startsWith(`i__const_`)&&(r=r.substring(9),r=r.substring(0,r.length-2));let o=i.prefix??``;return i.classNames===`camel`?o+t(r):i.classNames===`kebab`?o+n(r):a.includes(r)?o+e(a.indexOf(r)):o+e(a.push(r)-1)}return[r(),{name:`@almighty-shogun/vite-preset/css-modules`,config:()=>({css:{modules:{generateScopedName:i.generateScopeName??o}}})}]};export{i as cssModules};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["className","cssModules","visitedClasses","generateScopeName","name","prefix","options","camelCase","kebabCase","patchCssModules"],"sources":["../src/cssModules.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport className from 'css-class-generator';\nimport { camelCase, kebabCase } from 'change-case';\nimport { patchCssModules } from 'vite-css-modules';\n\ntype Options = {\n readonly classNames?: 'mangled' | 'camel' | 'kebab';\n readonly generateScopeName?: (name: string, filename: string, css: string) => string;\n readonly prefix?: string;\n};\n\nconst cssModules = (options: Options = {}): Plugin[] => {\n const visitedClasses: string[] = [];\n\n function generateScopeName(name: string): string {\n if (name.startsWith('i__const_')) {\n name = name.substring(9);\n name = name.substring(0, name.length - 2);\n }\n\n const prefix = options.prefix ?? '';\n\n if (options.classNames === 'camel') {\n return prefix + camelCase(name);\n }\n\n if (options.classNames === 'kebab') {\n return prefix + kebabCase(name);\n }\n\n if (visitedClasses.includes(name)) {\n return prefix + className(visitedClasses.indexOf(name));\n }\n\n return prefix + className(visitedClasses.push(name) - 1);\n }\n\n return [\n patchCssModules() as unknown as Plugin,\n {\n name: '@almighty-shogun/vite-preset/css-modules',\n config: () => ({\n css: {\n modules: {\n generateScopedName: options.generateScopeName ?? generateScopeName\n }\n }\n })\n }\n ];\n};\n\nexport default cssModules;\n"],"mappings":"A,6IAWA,MAAMC,GAAc,EAAmB,CAAC,IAAgB,CACpD,IAAMC,EAA2B,CAAC,EAElC,SAASC,EAAkB,EAAsB,CACzCC,EAAK,WAAW,WAAW,IAC3B,EAAOA,EAAK,UAAU,CAAC,EACvB,EAAOA,EAAK,UAAU,EAAGA,EAAK,OAAS,CAAC,GAG5C,IAAMC,EAASC,EAAQ,QAAU,GAcjC,OAZIA,EAAQ,aAAe,QAChBD,EAASE,EAAUH,CAAI,EAG9BE,EAAQ,aAAe,QAChBD,EAASG,EAAUJ,CAAI,EAG9BF,EAAe,SAASE,CAAI,EACrBC,EAASL,EAAUE,EAAe,QAAQE,CAAI,CAAC,EAGnDC,EAASL,EAAUE,EAAe,KAAKE,CAAI,EAAI,CAAC,CAC3D,CAEA,MAAO,CACHK,EAAgB,EAChB,CACI,KAAM,2CACN,YAAe,CACX,IAAK,CACD,QAAS,CACL,mBAAoBH,EAAQ,mBAAqBH,CACrD,CACJ,CACJ,EACJ,CACJ,CACJ,E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@almighty-shogun/vite-preset",
|
|
3
|
+
"description": "CSS Modules class name generation for Vite projects.",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsdown",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
10
|
+
"dev": "tsdown --watch --no-clean"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"provenance": true
|
|
15
|
+
},
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Almighty-Shogun",
|
|
18
|
+
"email": "alm1ghtyshogun1998@gmail.com",
|
|
19
|
+
"url": "https://shogun.ms"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Almighty-Shogun/node-packages.git",
|
|
24
|
+
"directory": "packages/vite-preset"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"typings": "./dist/index.d.mts",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"default": "./dist/index.mjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"src",
|
|
38
|
+
"dist",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"CODEOWNERS"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"change-case": "^5.4.4",
|
|
44
|
+
"css-class-generator": "^2.0.0",
|
|
45
|
+
"vite-css-modules": "^1.16.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"vite": "^8.3.4"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^26.6.5",
|
|
52
|
+
"tsdown": "^0.23.1",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"vite": "^8.3.4"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import className from 'css-class-generator';
|
|
3
|
+
import { camelCase, kebabCase } from 'change-case';
|
|
4
|
+
import { patchCssModules } from 'vite-css-modules';
|
|
5
|
+
|
|
6
|
+
type Options = {
|
|
7
|
+
readonly classNames?: 'mangled' | 'camel' | 'kebab';
|
|
8
|
+
readonly generateScopeName?: (name: string, filename: string, css: string) => string;
|
|
9
|
+
readonly prefix?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const cssModules = (options: Options = {}): Plugin => {
|
|
13
|
+
const visitedClasses: string[] = [];
|
|
14
|
+
|
|
15
|
+
function generateScopeName(name: string): string {
|
|
16
|
+
if (name.startsWith('i__const_')) {
|
|
17
|
+
name = name.substring(9);
|
|
18
|
+
name = name.substring(0, name.length - 2);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const prefix = options.prefix ?? '';
|
|
22
|
+
|
|
23
|
+
if (options.classNames === 'camel') {
|
|
24
|
+
return prefix + camelCase(name);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (options.classNames === 'kebab') {
|
|
28
|
+
return prefix + kebabCase(name);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (visitedClasses.includes(name)) {
|
|
32
|
+
return prefix + className(visitedClasses.indexOf(name));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return prefix + className(visitedClasses.push(name) - 1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
name: '@almighty-shogun/vite-preset',
|
|
40
|
+
|
|
41
|
+
config: () => ({
|
|
42
|
+
css: {
|
|
43
|
+
modules: {
|
|
44
|
+
generateScopedName: options.generateScopeName ?? generateScopeName
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default (options: Options = {}): Plugin[] => {
|
|
52
|
+
return [
|
|
53
|
+
patchCssModules() as unknown as Plugin,
|
|
54
|
+
cssModules(options),
|
|
55
|
+
];
|
|
56
|
+
};
|
package/src/deps.d.ts
ADDED
package/src/index.ts
ADDED