The most important implication of how Tailwind extracts class names is ์์ค ํ์ผ์์ ์์ ํ๊ณ unbroken strings๋ก ์กด์ฌํ๋ ํด๋์ค๋ง ์ฐพ๋๋ค๋ ๊ฒ์ ๋๋ค.
If you use string interpolation or concatenate partial class names together, Tailwind will not find them and therefore will not generate the corresponding CSS:
๋ฌธ์ ์ํฉ ๐ฟ
x: e.clientX, y: e.clientY
obj state๋ฅผ ์ค์ .ํ์ง๋ง px๊ฐ์ ์ ๋๋ก ๋ฐ๋๋๋ฐ, ๋ง์ฐ์ค ํฌ์ธํฐ์ ์์นํ ๊ณณ์ element๊ฐ ์์ฑ๋์ง ์์๋ค.
before:
TailwindCSS
The way Tailwind scans your source code for classes is intentionally very simple. ์ค์ ๋ก ์ฝ๋๋ฅผ ํ์ฑํ๊ฑฐ๋ ์คํํ์ง ์๊ณ , ์ ๊ท ํํ์์ ์ฌ์ฉํ์ฌ ํด๋์ค ์ด๋ฆ์ด ๋ ์ ์๋ ๋ชจ๋ ๋ฌธ์์ด์ ์ถ์ถํฉ๋๋ค.
We donโt just limit our search to
class="~"
attributes because you could be using classes anywhere, like in some JavaScript for toggling a menu:์ด ๋งค์ฐ ๊ฐ๋จํ ์ ๊ทผ ๋ฐฉ์์ ์ฌ์ฉํจ์ผ๋ก์จ, Tailwind๋
JSX
์ ๊ฐ์ ์ด๋ค ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์๋ ๋งค์ฐ ์ ๋ขฐ์ฑ ์๊ฒ ์๋ํฉ๋๋ค.Dynamic class names
The most important implication of how Tailwind extracts class names is ์์ค ํ์ผ์์ ์์ ํ๊ณ unbroken strings๋ก ์กด์ฌํ๋ ํด๋์ค๋ง ์ฐพ๋๋ค๋ ๊ฒ์ ๋๋ค.
If you use string interpolation or concatenate partial class names together, Tailwind will not find them and therefore will not generate the corresponding CSS:
โ Donโt construct class names dynamically
In the example above, the strings text-red-600 and text-green-600 do not exist, so Tailwind will not generate those classes.
Instead, make sure any class names youโre using exist in full:
๐ต Always use complete class names
React๋ Vue์ ๊ฐ์ ์ปดํฌ๋ํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ, ์ด๋ props๋ฅผ ์ฌ์ฉํ์ฌ ๋์ ์ผ๋ก ํด๋์ค๋ฅผ ๊ตฌ์ฑํด์๋ ์ ๋๋ค๋ ์๋ฏธ์ ๋๋ค.
โ Donโt use props to build class names dynamically
Instead, map props to complete class names that are statically detectable at build-time:
๐ต Always map props to static class names
ํ์ง๋ง, ์ํ๋ ์์น์ ์์๋ฅผ ์์น์ํค๊ณ ์ถ์ผ๋ฉด, ๊ฐ์ ๋์ ์ผ๋ก ๊ด๋ฆฌํด์ผํ๋ค.