-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using pug with vite+tailwindcss in JIT mode causes HMR to not detect changes in new css compiled classes #4588
Comments
Tailwind JIT may register any file as a dependency to a CSS file, these include the vite/packages/vite/src/node/server/hmr.ts Lines 227 to 231 in ed16488
But the .vue of the pug template will generate a module of TestPug.vue?vue&type=template&lang.js . This module is not dependent to css, and its isSelfAccepting is true, so modifying the pug template will only request this module again, and will not update css.
|
If I explicitely add I had a look at the way tailwind registers the purge list with postcss. If I understand correctly, in order to fix this bug we would need to do the same thing (https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#31-use-messages-to-specify-dependencies) at the creation of the virtual module ending with I am not familiar at all with this project, would this place be the right to do so? vite/packages/plugin-vue/src/main.ts Lines 225 to 234 in a6f5aa7
|
I have the same issue however with a slightly different behavior, when I change some css classes in the pug template sometimes the changes are picked up and sometimes I need a full page refresh (95% of the times)
there's this this is especially troublesome because since it doesn't fail 100% of the time you are always unsure if the css changes you made are being taken into account or not. |
out of desperation I reverted some views back to normal html files and I have the same issue. |
Hey Tailwind maintainer here! I just tried to debug this issue and I think (unless I'm missing something) that this is a Vite issue and not a Tailwind issue: tailwindlabs/tailwindcss#6340 (comment) The TL;DR of my comment is, if you have this module.exports = {
plugins: [
/* This is a new plugin, unrelated to Tailwind */
function (root) {
console.log('A change happened!')
return root
},
/* Other plugins in the chain */
require('tailwindcss'),
require('autoprefixer')
]
} Then you will notice that the log is called when you change the Since PostCSS is never called again, Tailwind is not called and doesn't know about this change. |
i had a similiar problem with const reloadTailwind = {
name: 'reload-tailwind',
transformIndexHtml(html) {
return html.replace('tailwind.css', 'tailwind.css?v=' + new Date().getTime())
}
} |
Unfortunately none of these workarounds is working for me, and a related bug #5270 means that I can't manually access I was hoping to use something to this effect:
|
Manual modification based on above pull request is to edit if (!templateModule) {
affectedModules.add(mainModule);
} else if (mainModule && !affectedModules.has(mainModule)) {
const styleImporters = [...mainModule.importers].filter((m) => /\.css/.test(m.url));
styleImporters.forEach((m) => affectedModules.add(m));
} |
Describe the bug
The HMR seems to have a different behavior between regular HTML and pug templates in vue sfc.
When using Tailwind in JIT mode, the HTML template works well and the HMR picks up when tailwind has recompiled the index.css.
But when using a pug template, the HMR only detects a change in the vue file (so the content and the classes are updated) but it does not detect a change in the index.css, and the classes are not applied.
A page reload, or any modification to the index.css (even through a html template), allows us to eventually see the styles.
Reproduction
https://github.com/gbea/vite-pug-tailwind-JIT-bug
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: