<link rel="stylesheet" href="tailwindcss" />
not works
#16937
Replies: 4 comments
-
I would postulate that the Vite HTML parser doesn't understand the
So you could create a @import "tailwindcss"; And have that linked in your <head>
<title>react-boilerplate</title>
- <link rel="stylesheet" href="tailwindcss/index.css" />
+ <link rel="stylesheet" href="/src/styles.css" />
</head>
<body> |
Beta Was this translation helpful? Give feedback.
-
Thanks. I prefer If |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if Tailwind can do anything about this, but from looking at the Vite code, it processes HTML nodes for asset inclusion: // For asset references in index.html, also generate an import
// statement for each - this will be handled by the asset plugin
const assetAttributes = getNodeAssetAttributes(node)
for (const attr of assetAttributes) { And we can see the test for test('handles link with allowed rel', () => {
const node = getNode('<link rel="stylesheet" href="style.css">')
const attrs = getNodeAssetAttributes(node)
expect(attrs).toHaveLength(1)
expect(attrs[0]).toHaveProperty('type', 'src')
expect(attrs[0]).toHaveProperty('key', 'href')
expect(attrs[0]).toHaveProperty('value', 'style.css')
expect(attrs[0].attributes).toEqual({
rel: 'stylesheet',
href: 'style.css',
})
}) Thus, assetAttributes = [
{
type: 'src',
key: 'href',
value: 'tailwindcss',
attributes: {
rel: 'stylesheet',
href: 'tailwindcss',
},
}
] We skip through to the relevant conditional which then leads us to this significant conditional: if (
node.nodeName === 'link' &&
isCSSRequest(url) &&
// should not be converted if following attributes are present (#6748)
!('media' in attr.attributes || 'disabled' in attr.attributes)
) { Specifically, the export const isCSSRequest = (request: string): boolean =>
CSS_LANGS_RE.test(request) export const CSS_LANGS_RE =
/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/ And thus, for Vite to load a |
Beta Was this translation helpful? Give feedback.
-
What version of Tailwind CSS are you using?
v4.0.9
What build tool (or framework if it abstracts the build tool) are you using?
Vite 6.2.0
What version of Node.js are you using?
v22.14.0
What browser are you using?
Chrome
What operating system are you using?
Ubuntu
Reproduction URL
https://github.com/zanminkian/react-boilerplate/tree/tw-link-issue
Describe your issue
I have an
index.html
:After building by vite, the style not works. But if I change
<link rel="stylesheet" href="tailwindcss" />
to<link rel="stylesheet" href="tailwindcss/index.css" />
, it works.Reproduced steps
git clone git@github.com:zanminkian/react-boilerplate.git
cd react-boilerplate && git checkout tw-link-issue && pnpm i && pnpm build
There are no☹️
css
files indist
folder.Beta Was this translation helpful? Give feedback.
All reactions