英文:
Classes brought from Team A and Team B polluting the same global namespace
问题
在这种情况下,如何解决这个问题?
英文:
I am new to Tailwind CSS but there is something that confuses me.
Let's run a scenario:
Team A
- builds a UI component library using TailwindCSS (Button, Forms, Dialog, etc)
- publish NPM package where exports
index.ts
andtheme/tailwind.css
Team B
npm install
Team A library. Importstheme/tailwind.css
into their applicationmain.ts
(entry point).
At this point, their main.ts
should have
import { Button } from '@team-a/ui`
import '@team-a/ui/theme/tailwind.css` // tailwind classes coming from Team A
import `./theme/main.css` // tailwind CSS global file belonging to Team B
At this point in time, in the <style>
tags in the head, we will have classes brought from Team A and Team B, polluting the same global namespace.
How do you get around this issue?
答案1
得分: 1
以下是翻译好的部分:
- 使用@layers,
- 将CSS的作用范围限定为仅适用于特定的标签及其子元素。通常,框架会处理这一点,比如React使用CSS模块,Angular使用视图封装,但也可以使用PostCSS或Sass实现。
- 使用每个团队的独特字符串作为前缀,如果它们生成分离的Tailwind输出CSS。
英文:
There a few ways to avoid this, but if both teams uses tailwind there should not be any issue. unless you have custom CSS that for example overrides custom properties at the :root.
Regardless here a few ways to avoid clashing CSS styles.
- use @layers,
- Scope the CSS to apply only to a specific tag and below. This is a tricky one, usually frameworks will handle that, react with CSS modules, angular with view encapsulation, but it is possible with postcss or sass.
- Prefix the tailwind config with each team unique string, if they build separated tailwind output CSS.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论