This repository was archived by the owner on May 28, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork1
NiceLabs/typed-css-modules
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Creates TypeScript definition files fromCSS Modules .css files.
If you have the following css,
/* locals.css */.local {}.local-1 {}
typed-css-modules creates the following .d.ts files from the above css:
/* locals.css.d.ts */interfaceILocals{'local':string;'local-1':string;[name:string]:string;}declareconstlocals:ILocals;export=locals;
So, you can import CSS modules' class or variable into your TypeScript sources:
/* app.ts */import*aslocalsfrom'./locals.css';console.log(locals.local);console.log(locals['local-1']);
npm install -D @nice-labs/typed-css-modules
import*asfsfrom'fs';import{promisify}from'util';import{getModuleTokens,createTypeHint}from'@nice-labs/typed-css-modules';constreadFile=promisify(fs.readFile);asyncfunctionmain(){constsource=awaitreadFile('locals.css');consttokens=awaitgetModuleTokens(source);// ["local", "local-1"]consttypeHint=createTypeHint(tokens);// d.ts file content}main();
// webpack.config.tsimportwebpackfrom"webpack";import*asTypedCSSModulesfrom"@nice-labs/typed-css-modules";constconfigure:webpack.Configuration={module:{rules:[// ...{test:/\.css$/,use:[[TypedCSSModules.loader,{mode:"local",// "local" | "global" (default is "local")camelCase:false// boolean (default is false)}],require.resolve("postcss-loader"),]}// ...]}};exportdefaultconfigure;
// webpack.config.tsimportTypedCSSModulesPluginfrom'@nice-labs/typed-css-modules';constconfigure:webpack.Configuration={plugins:[// ...newTypedCSSModulesPlugin({mode:'local',// "local" | "global" (default is "local")camelCase:false,// boolean (default is false)filesPattern:'./src/**/*.css',// string | string[] (default is "./src/**/*.css")}),// ...],};exportdefaultconfigure;
This software is released under the MIT License, see LICENSE.txt.
About
Typed CSS Modules
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.