在文件中托管代码(graphql/css/js/html)很棒。
我使用 TailwindCSS 库为我的组件设置样式,并使用classnames包动态插入类。
我还使用Prettier来格式化我的代码。问题是它会格式化我的类规则,每行一个类,这很快就会使我的文件膨胀。
通缉:
const container = cn("flex", "flex-col", "min-h-lg", "mb-12", "transition-opacity", "duration-500", "ease-in-out");
const buttons = cn(
"inline-grid", "row-gap-5", "col-gap-10", "grid-rows-5", "grid-flow-col",
"sm:grid", "sm:grid-cols-3",
);
const character = cn(
"hidden", "row-span-5", "h-48", "place-self-end", "origin-center",
"animation-once", "animation-ease-out", "animation-0.8s", "animation-fill-forwards",
"sm:block", "sm:animation-lightspeedin",
);
我得到的更漂亮:
const container = cn(
"flex",
"flex-col",
"min-h-lg",
"mb-12",
"transition-opacity",
"duration-500",
"ease-in-out"
);
const buttons = cn(
"inline-grid",
"row-gap-5",
"col-gap-10",
"grid-rows-5",
"grid-flow-col",
"sm:grid",
"sm:grid-cols-3"
);
const character = cn(
"hidden",
"row-span-5",
"h-48",
"place-self-end",
"origin-center",
"animation-once",
"animation-ease-out",
"animation-0.8s",
"animation-fill-forwards",
"sm:block",
"sm:animation-lightspeedin"
);
如您所见,它很快就会失控。我想知道其他具有类似堆栈的人正在做什么来保持他们的文件可读。我一直在努力寻找少于 100 行的文件,但是使用 prettier+tailwindcss 已经不可能了。prettier-ignore-{start,end}
如果 js/jsx/ts/tsx 文件支持它,我会选择的。你忽略每一条规则吗?
// prettier-ignore
const container = cn("flex", "flex-col", "min-h-lg", "mb-12", "transition-opacity", "duration-500", "ease-in-out");
// prettier-ignore
const buttons = cn(
"inline-grid", "row-gap-5", "col-gap-10", "grid-rows-5", "grid-flow-col",
"sm:grid", "sm:grid-cols-3",
);
// prettier-ignore
const character = cn(
"hidden", "row-span-5", "h-48", "place-self-end", "origin-center",
"animation-once", "animation-ease-out", "animation-0.8s", "animation-fill-forwards",
"sm:block", "sm:animation-lightspeedin",
);
或者您是否将所有类移动到文件底部以使其不那么可见/减少滚动以获取组件的需要?prettier-ignore-{start,end}
我想我会两者都做,并在可用时将它们移回文件顶部。