-
Notifications
You must be signed in to change notification settings - Fork 11
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
Can't get to work with Tailwind #6
Comments
Hi, Which PrimeVue version are you using? |
Thanks a lot for the report! I'll work on it and get back to you. |
Same for me with this config: import { usePassThrough } from 'primevue/passthrough'
import Tailwind from 'primevue/passthrough/tailwind'
const primeVueTailwindOverrides = {
datatable: {
column: {
bodyCell: ...
}
}
...
}
const passThroughStyles = usePassThrough(Tailwind, primeVueTailwindOverrides)
export default defineNuxtConfig({
primevue: {
options: { pt: passThroughStyles, unstyled: true },
},
...
}) Except some styles seem to randomly work. Is this the correct way to add overrides to the Tailwind styles when using the module, btw? It's not mentioned in the docs. |
Same here, I'd be happy to sponsor a coffee once this is fixed ☕
I am using the following versions: |
Hi all, I researched this issue in detail. The main reason for these issues is that there are non-serializable (exp; function) definitions in pt presets. Details; https://nuxt.com/docs/guide/going-further/runtime-config#serialization For example, when you use the following config, it works fine. // nuxt.config.js
primevue: {
options: {
pt: {
button: {
root: 'MY_BUTTON_CLASS' // (serializable)
}
}
}
} But, the following config doesn't work; // nuxt.config.js
primevue: {
options: {
pt: {
button: {
root: () => 'MY_BUTTON_CLASS' // OR `root: function() { return { class: 'MY_BUTTON_CLASS' } }` etc. (non-serializable)
}
}
}
} Finally, I think there are 2 ways to solve this issue.
// nuxt.config.js
primevue: {
usePrimeVue: false,
// options -> this key is unnecessary.
...
}
Transform;
WDYT? |
Either way, this would still force you to keep your custom styles in the Nuxt config file, right? Because currently, you have to restart the dev server for any style change (unless I'm missing something), which is not sustainable. With the implementation before this module, i.e. with a custom Nuxt plugin, only the page is reloaded (which is still a pain compared to HMR). |
HMR is entirely related to Nuxt's configurations(nuxt/issues/18964). As far as I know, you can establish an HMR structure in Nuxt using Vite's infrastructure. The details can be found in the Vite documentation. https://vitejs.dev/guide/api-hmr.html#hmr-api Regarding the main topic, if you follow a similar path to the solution I initially suggested (think of it as if you were not using the Nuxt-PrimeVue module), all configurations are within your control. You can adjust PrimeVue options according to your needs. You can even perform overrides using the 'UsePassThrough' feature. My second suggestion is to have a preset ready. With this prepared preset, the nuxt-primevue module creates a plugin internally and imports it. Then, it adds its value to the options section when registering for PrimeVue. |
I mean that you can't get HMR (or auto page reload) to work for changes to
i.e. what does this module do if I'm creating a Nuxt plugin manually anyway? (which is what I was already doing before this existed). I'm confused 🙂 Also, I saw in this discussion that |
So let's start with the question of what the module is needed for.
Code Refs; We created the nuxt-primevue module to fix the issues I mentioned above. This module will be of great importance in our new styled mode structure in the future.
What I'm talking about here is not entirely about you creating a plugin. Where you will register the components, PrimeVue, Services is up to you. So what does the Code Ref: https://github.com/primefaces/primevue-nuxt-module/blob/main/src/module.ts#L79
Yes, our suggestion is that users create their own presets instead of overriding them. This allows users to establish a more controllable structure. So why don't we recommend
If we used the bg-blue class to change the bg of a button in the preset and you override it with I hope these details didn't confuse you even more :) |
Personally I would not want to keep raw PT config in nuxt config, we'll discuss this for sure at earliest. |
I had success now, I followed @mertsincan first proposal: Added: import PrimeVue from "primevue/config";
import Tailwind from "primevue/passthrough/tailwind";
export default defineNuxtPlugin((app) => {
app.vueApp.use(PrimeVue, { unstyled: true, pt: Tailwind });
}); And the following nuxtconfig.ts // https://nuxt.com/docs/api/configuration/nuxt-config
/** @type {import('nuxt').Config} */
export default defineNuxtConfig({
devtools: { enabled: true },
css: ["primeicons/primeicons.css"],
postcss: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
modules: ["nuxt-primevue", "@nuxtjs/tailwindcss"],
primevue: {
usePrimeVue: false,
},
}); So there's no raw PT config (as far as I understand); however, it would be just a tiny tad nicer if I wouldn't need the But for now, at least all services, components and directives are registered globally without manual intervention, so that is already a big plus for me :) |
@mertsincan Thank you very much for the detailed explanation. That, along with the implementation example from @micheee makes it clear what the benefit of the module is compared to a 100% custom plugin implementation. So I guess now the question becomes, how can the same DX be achieved, without the need for |
I'm not 100% sure if everything is working, but for me, it's working quite well so far: I can add |
Thanks a lot, @micheee @deepfriedmind ;) In addition, when you set @cagataycivici, I totally agree with you. But we should not forget that there is no rule that we cannot use pt in a module. We cannot use pt structures containing non-serializable definitions. This is also a situation related to Nuxt. If they do a study on this in the future, we can immediately integrate the improvements into the nuxt-primevue module. Details; #6 (comment) |
Good morning, i run into the same problem with my primevue-nuxt module. Only solution i found was NOT to include pt in the module configuration, but configure it in app.vue:
After some tests with this module i would do it the same way. Easy to switch themes like in the demo from @cagataycivici . Greetings, Tom |
Hi, Thanks a lot for your feedback, @sfxcode ;) We are always open to alternative solutions. Frankly, I have a few ideas, I plan to discuss them with the team and share them with you. |
I installed the Nuxt module today and I'm also having styling issues with Tailwind. I have a custom PrimeVue theme and I'm using Tailwind mostly for the utility classes, so I'm not using pass-through, but Tailwind's styling are taking precedence over PrimeVue's theme. I tried changing the layers order but it didn't work:
|
Hi all, I'm working on new module options. I will complete it asap and share it with you. |
Hi all, I added the Usage with
🚀 Thank you very much everyone for all the feedback 🤙 |
Hi @mertsincan thanks very much |
Hi @alterhu2020, The new version has not been released yet. I plan to release it with the PrimeVue version tomorrow. You can try its after it is released. I'm also updating the documentation. Best Regards, |
Hi all,
|
Nuxt-PrimeVue + Tailwind starter updated; https://github.com/primefaces/primevue-examples/tree/main/nuxt-styled-tailwind New module doc; https://primevue.org/nuxt/ |
This tripped me up for a bit so it should probably be mentioned in the docs that you need to add this file as a "content file" in your Tailwind config as well, e.g.: content: [
'./node_modules/primevue/**/*.{vue,js,ts,jsx,tsx}',
'./assets/presets/custom.js',
] Otherwise, all the Tailwind classes used only in that file will be purged and won't work. Oh, and to reiterate, this method allows for auto reload on save, but not HMR, as far as I can tell. |
Hi, I was looking forward to importPT, but it doesn't seem to work for me out of some reason ... After couple of tries, I did test also on (unstyled) Nuxt-PrimeVue + Tailwind starter and I do struggle with same error also there (full console output at the bottom). I must be doing something wrong, but I'm unable to figure it out... Is that starter project supposed to be working with latest nuxt+nust-primevue+tailwind? (the "styled" version works for me) Node version v21.3.0 (tried also v18), [email protected], [email protected], @nuxtjs/[email protected] Thanks!
|
Oh, sorry, I forgot to include import { resolve } from 'path'
...
export default defineNuxtConfig({
...
primevue: {
options: { unstyled: true, ripple: true },
cssLayerOrder: 'tailwind-base, primevue, tailwind-utilities',
importPT: { as: 'Lara', from: resolve(__dirname, './assets/primevue-themes/lara/') },
components: {
exclude: ['Editor', 'Chart'],
},
}, And the second test - using the unstyled starter, I'm using that as-is, so: import * as path from 'path';
export default defineNuxtConfig({
modules: ['@nuxtjs/tailwindcss', "nuxt-primevue"],
primevue: {
options: { unstyled: true },
cssLayerOrder: "tailwind-base, primevue, tailwind-utilities",
importPT: { as: 'Lara', from: path.resolve(__dirname, './presets/lara/') },
... I tried bunch of different 'from' attributes: Unfortunately, with no luck :( It looks like "something" might be broken in my npm packages then? |
Hmm. interesting. Could you please try it after deleting package-lock.json, node_modules and .nuxt, then npm install. Do you confirm that you are using our sample project and have not changed anything? |
I do confirm. I start with project nuxt-unstyled-tailwind and do only As far as I can tell, I do not have nuxt/vue/primevue/tailwind installed globally: c:\>npm list -g --depth=0
C:\Program Files\nodejs -> .\
+-- [email protected]
`-- [email protected] |
I have the same problem. I'm working on windows 11. Isn't the problem only in windows? |
I checked your error again. |
I had the exact same issue as you @zelarg and changing the
|
@craigjamesdobson Perfect, thanks! That fixed the problem on Windows for me. |
|
thank u bro @craigjamesdobson you saved my project! |
@craigjamesdobson another one who has to thank you 🥂 |
I followed the instructions on https://tailwind.primevue.org/nuxt/#preset on Windows 11 and was unable to make it work until I found the solution in the last comments of this issue. @mertsincan Maybe it is worth to update the documentation and examples to get rid of I.e.: importPT: { as: 'Lara', from: '~/primevue/presets/lara' }, Tested on Windows 11. Didn't test on Linux/Mac yet, but probably it will work as the path resolving is working correctly in other |
Love to see this new Nuxt module as well as the TailwindCSS version of PrimeVue! I have been using PrimeVue as a Nuxt plugin as well as Tailwind so far, with this setup:
Unfortunately, I can't get it work with the new module. I have something like this in nuxt.config.js:
Both Tailwind and PrimeVue seem to work independently, but the stylings are not applied. I have also tried applied "MyDesignSystem" as per https://primevue.org/tailwind/, which also doesn't seem to work. Any ideas for how to fix this?
The text was updated successfully, but these errors were encountered: