TypeStyle类型安全的CSS写法

TypeScript 的 CSS 写法,一直是前端圈的痛点。TypeStyle算是个解法,用起来就像在写 JS,啥 AST 转换、模块加载器全都不用操心,直接上就行。整个库就 6k,简直轻到飞起。

和你平常在 Webpack 里用的CSS Modules有点像,但TypeStyle更类型安全。CSS 写完直接能享受编辑器提示,属性打错了还能立马报错,对写 TS 的你来说简直太友好了。

适配也挺广,ReactVueAngular通通不在话下。不用装 loader,也不用配置 half 天,npm 装完就能用,真的是“零配置上手”。

比如你要写个 display: flex 的容器,代码长这样:

const container = style({
  display: 'flex',
  justifyContent: 'center',
});

直接在 JSX 里用 className={container},一切都顺。

如果你平时项目里 TS 比较多,又不想搞那么多 CSS 文件,TypeStyle真的是个省心的选择。想了解更多可以看看这篇文章,讲得还挺细。

zip
typestyle-master.zip 预估大小:31个文件
folder
typestyle-master 文件夹
file
.travis.yml 32B
file
tsconfig.es2015.json 216B
file
package.json 1KB
folder
umd 文件夹
file
index.html 223B
file
index.min.html 227B
file
alm.json 68B
file
LICENSE 1KB
folder
dist 文件夹
folder
umd 文件夹
file
typestyle.js 34KB
file
typestyle.min.js 11KB
file
CONTRIBUTING.md 511B
folder
src 文件夹
folder
internal 文件夹
file
utilities.ts 3KB
file
typestyle.ts 6KB
file
formatting.ts 1KB
folder
tests 文件夹
file
extend.ts 3KB
file
media.ts 2KB
file
supports.ts 416B
file
raw.ts 581B
file
rule.tsx 2KB
file
fontFace.tsx 477B
file
keyframes.ts 601B
file
basic.tsx 5KB
file
types.ts 4KB
file
index.ts 3KB
file
.npmignore 151B
file
tsconfig.json 358B
file
.gitignore 732B
file
webpack.config.js 577B
file
CHANGELOG.md 1KB
file
.npmrc 19B
file
README.md 3KB
file
.editorconfig 156B
zip 文件大小:32.54KB