Can we force Tailwindcss(nuxt ui) scan module for css
I am trying to create a module on top nuxt ui what i need to somehow make tailwindcss compiler to also scan component in module for tailwind css(nuxt ui)
19 Replies
Hi @Muhammad Khizar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, you can force Tailwind CSS (including when using Nuxt UI) to scan your module’s components for utility classes. When authoring a Nuxt module, you should use the Nuxt Kit’s
installModule
utility to programmatically add Tailwind CSS and configure its content
option to include your module’s component files.
Here’s how you can do it in your module:
This ensures that Tailwind will scan all your module’s components and runtime files for utility classes, so styles are generated correctly—even for components provided by your module. This approach is officially documented for both Nuxt 3 and Nuxt 4 module authors Using Other Modules in Your Module.
If you are using Nuxt UI, you can combine this with the Nuxt UI module in your nuxt.config.ts
as usual. Just make sure your module’s components are included in the Tailwind content
configuration as shown above.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1079765697753784431> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I am using nuxt ui
can still do it?
@kapa.ai ?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Yes, you can force Tailwind CSS (including when using Nuxt UI) to scan your module for utility classes by configuring the Tailwind
content
option to include your module’s component files. When creating a Nuxt module, you should use the Nuxt Kit’s installModule
utility and specify the paths to your module’s components in the content.files
array. Here’s an example from the official documentation:
This approach ensures that Tailwind will scan all your module’s components and runtime files for utility classes, so styles are generated correctly—even for components provided by your module. This method is officially documented for Nuxt module authors and is compatible with Nuxt UI as well. For more details, see the official Nuxt documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1079765697753784431> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai
and also i change nuxt ui as it using this but still not work
and also i change nuxt ui as it using this but still not work
Let me check the knowledge base for you again. One moment! :books:
----------------------
You are correct: the use of
-
Nuxt 4 Module Definition
Nuxt PR: allow modules to specify dependencies ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
installModule
is now deprecated for specifying dependencies between Nuxt modules. This is confirmed in the official Nuxt documentation and recent pull requests. The new recommended approach is to use the moduleDependencies
property in your module definition. This allows you to declare dependencies and even override their configuration, and ensures that dependencies are resolved before your module runs. Here’s how you can do it:
This approach is now the recommended way to specify module dependencies and configuration overrides, and it will ensure that Tailwind CSS (and Nuxt UI) are properly set up to scan your module’s components for utility classes. The use of installModule
is deprecated because it has several shortcomings, including not affecting already-installed modules and overriding user configuration in ways that are not always desirable. You can read more about this change in the Nuxt 4 module author guide and the related pull request.
If you are still experiencing issues with Tailwind not scanning your module, ensure that your paths are correct and that you are using the new moduleDependencies
approach as shown above. If you need to support older Nuxt versions, you may need to use installModule
as a fallback, but for Nuxt 4 and forward, moduleDependencies
is the way to go.
Summary:-
installModule
is deprecated for module dependencies.
- Use moduleDependencies
in your module definition to declare and configure dependencies.
- This ensures Tailwind and Nuxt UI are set up correctly for your module’s components to be scanned for CSS classes.
References:Nuxt 4 Module Definition
Nuxt PR: allow modules to specify dependencies ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@1079765697753784431> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai @nuxtjs/tailwindcss not install when we use nuxt ui
Let me check the knowledge base for you again. One moment! :books:
----------------------
When you use Nuxt UI, you do not need to install
- Do not install
@nuxtjs/tailwindcss
separately. Nuxt UI manages Tailwind CSS integration for you. The official Nuxt UI installation guide instructs you to simply install @nuxt/ui
and import Tailwind CSS in your CSS file:
Then, in your app/assets/css/main.css
:
And in your nuxt.config.ts
:
There is no need to add @nuxtjs/tailwindcss
to your modules—Nuxt UI handles Tailwind for you automatically. If you use both, you may encounter conflicts or unexpected behavior. Just follow the Nuxt UI documentation and you will have Tailwind CSS support out of the box Nuxt UI Installation.
If you are building a module on top of Nuxt UI and need to ensure Tailwind scans your files, you should use the @source
directive in your CSS to include your content or component directories, as described in the Nuxt UI docs Nuxt UI + Content Integration.
If you need to customize Tailwind’s behavior further, you can do so using the CSS-first configuration approach with the @theme
and @source
directives in your CSS file, rather than a separate Tailwind config file Nuxt UI Design System.
Summary:- Do not install
@nuxtjs/tailwindcss
when using Nuxt UI; Nuxt UI manages Tailwind for you.
- Use the @import "tailwindcss";
directive in your CSS.
- Use the @source
directive to ensure Tailwind scans your desired files if needed.
If you follow these steps and still have issues, please provide more details about your setup.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1079765697753784431> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai
is it correct it still not working changes it nuxt ui
Let me check the knowledge base for you again. One moment! :books:
----------------------
Your approach to using
Your current approach to force Tailwind scanning via
moduleDependencies
to ensure @nuxt/ui
is installed is correct according to the latest Nuxt module authoring practices. However, the way you are trying to configure Tailwind's content
scanning via moduleDependencies
for @nuxt/ui
is not supported or documented in the official sources. The content
property you are passing is not a recognized option for @nuxt/ui
and will not affect Tailwind's scanning behavior.
Key points from the knowledge sources:
- When using Nuxt UI, you do not need to install or configure @nuxtjs/tailwindcss
separately. Nuxt UI manages Tailwind CSS for you, and you should not attempt to override its Tailwind config via moduleDependencies
Nuxt UI Installation.
- To ensure Tailwind scans your module's components, the recommended approach is to use the @source
directive in your CSS file. For example, in app/assets/css/main.css
:
This tells Tailwind to scan your module's components for utility classes, as described in the Nuxt UI + Content integration docs Nuxt UI + Content Integration.
- The moduleDependencies
property is for ensuring modules are installed and for basic config overrides, but it does not provide a way to inject Tailwind's content
scanning paths into Nuxt UI or Tailwind itself Module Definition.
Summary of what you should do:
- Do not try to configure Tailwind's content
option via moduleDependencies
for @nuxt/ui
—this is not supported.
- Do use the @source
directive in your main CSS file to explicitly tell Tailwind to scan your module's components.
- Your use of addComponentsDir
, addPlugin
, and the composables hook is correct for exposing your module's features.
Example for your main CSS file:
Replace the path as needed to match your module's location.
If you follow this approach, Tailwind will scan your module's components for utility classes, and you do not need to modify the Nuxt UI or Tailwind config programmatically from your module.
If you are still having issues, please ensure:
- Your module is installed as a dependency in your Nuxt project.
- The @source
path is correct and points to your module's components.
- You have restarted your dev server after making these changes.
If you need more advanced Tailwind configuration, you may need to instruct users to extend their own Tailwind setup, but for most Nuxt UI-based projects, the @source
directive is the recommended and supported solution.
---
In summary:Your current approach to force Tailwind scanning via
moduleDependencies
is not supported. Use the @source
directive in your CSS as described in the Nuxt UI documentation to ensure Tailwind scans your module's components for utility classes Nuxt UI + Content Integration.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1079765697753784431> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I fixed it I am sharing here if anybody has issue here is fix found might not perfect but for me its working 🙂
create file in runtime tailwindcss
Do you really need this?
my idea is have nuxt ui component and then extend functionality on top it that's it their is any better idea
@Orbis
I mean the custom resolver stuff 🤔
I think nuxt.config css prop should do the job
oh ok can it do it for module too ? thanks