The functionality provided by Gridsome's Tailwind plugin does not seem to be functioning properly when using the "@

I'm trying to incorporate Tailwind's apply feature into my Gridsome project, but I keep getting an error saying that the css classes from Tailwind cannot be found.

To replicate this issue, follow these steps:

1) Start by creating a new Gridsome project

2) Next, install the Tailwind plugin using the following links: Github page Npm page

3) Create a CSS file in the assets folder and import it into main.js

import "~/assets/style.css"

4) Define a CSS class in the CSS file

5) Try using @apply in your CSS with a Tailwind component

However, despite properly importing the CSS file, only some elements like rounded are working while others like bg-blue-500 are not applying as expected.

Answer №1

Upon closer examination, it appears that there is a discrepancy between the documented behavior of Tailwind and its actual functionality.

According to the documentation regarding extracting components using @apply:

...Classes like this should be added directly after the @tailwind components directive to avoid specificity issues.

In practice, this results in a primary style.css file structured as follows:

@tailwind base;

@tailwind components;

// Please note: you could also include a custom CSS file here.
.btn-blue {
  @apply bg-blue-500 text-white font-bold py-2 px-4 rounded;
}
.btn-blue:hover {
  @apply bg-blue-700;
}

@tailwind utilities;

However, in reality, this consistently triggers a build error for a valid reason. Tailwind injects the utilities file with classes generated from the tailwind.config.js file.

CSS compilation occurs sequentially, so references to bg-blue-700 are unavailable for application until the utilities have been imported and processed.

Despite the recommendation in the documentation, rearranging component classes after the utilities section rectifies the compile error:

@tailwind base;

@tailwind components;

@tailwind utilities;

// Please note: you could also include a custom CSS file here.
.btn-blue {
  @apply bg-blue-500 text-white font-bold py-2 px-4 rounded;
}
.btn-blue:hover {
  @apply bg-blue-700;
}

Although not an ideal solution, this approach proved effective for me.

Answer №2

As stated in the official documentation, it is recommended to use @layers components {} to avoid unexpected behavior

Here's an example:

@tailwind base;

@tailwind components;

@tailwind utilities;

@layers components {
    // Note: you can also include a custom CSS file here.
    .btn-blue {
      @apply bg-blue-500 text-white font-bold py-2 px-4 rounded;
    }
    .btn-blue:hover {
      @apply bg-blue-700;
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Bootstrap 3.0 to create a dynamic design featuring multiple overlapping full-width background images

I'm currently in the process of constructing a static webpage utilizing Bootstrap 3.0. This particular page follows a storytelling format, consisting of multiple sections stacked on top of each other with background images. Text and additional images ...

The power of Vue reactivity in action with Typescript classes

Currently, I am working on a Vue application that is using Vue 2.6.10 along with Typescript 3.6.3. In my project, I have defined a Typescript class which contains some standard functions for the application. There is also a plugin in place that assigns an ...

Redirect visitors to specific webpage based on their stored cookie data

I am in the process of creating a website that will direct users to different locations based on their preferences. I have noticed other websites implementing a feature where they store user location choices and redirect them accordingly. Is using a cook ...

Encountered an issue while attempting to deploy my app on Heroku: received the error message "The requested resource does not have the 'Access-Control-Allow-Origin' header"

Hi fellow developers, I'm currently facing an issue while trying to upload a simple app to my Herokuapp. Every time I attempt to log in or sign up and establish a connection with the back-end, I encounter the following CORS error: "Access to fetch at ...

assign a key for browsing through results

I have an input field and I am using ajax to fetch results. Here is a simplified version of the code: <input placeholder="search here" id="search"></input> <div id="searchResults"> <a href="link">search result 1</a> ...

My Vuejs single page application features automatic page refreshing functionality

I created a single page application using vuejs, and I am currently facing the following issue: My navigation menu is working correctly with vue-router and vue-resource. When I click on a link in the menu, only a part of the page changes without refreshin ...

How can recursive data be displayed in a template?

I am working with a model in Django that has a ForeignKey pointing to itself, and I need to display all the data from the database using lists and sublists: Below is my model definition: class Place(models.Model) name = models.CharField(max_length=1 ...

Positioning the search bar to the left with react-bootstrap-table

Is there a way to move the search bar of react-bootstrap-table to the left instead of keeping it on the right? You can see an example here, at the bottom of the page: I know that you can create a custom search panel and input, but that seems like a compl ...

How about this: "Is it possible for the accordion to open when clicked and show

Screenshot illustrating the issue I need assistance with implementing a hover preview for the contents of the accordion, followed by keeping it open upon clicking. The codepen link is provided below for reference: Visit the codepen here <script src=&q ...

Delay Time for Closing Sub Menus When Multiple Dropdowns are Opened

My issue involves a multi-level drop-down menu that is solely constructed using CSS. The problem I am facing is that there is a delay of one second before the drop-down closes when the mouse is moved away. This delay causes multiple drop-down menus to stac ...

Unable to interpret data from the API

{ id: 8, customerName: "xyz", customerMobileNumber: "123456789", customerBillingAddress: "xyz address", customerShippingAddress: "xyz address", customerProductPurchasedDate: "2021-11-09T09:07:00.000Z", cust ...

Utilize Sass variables to store CSS font-size and line-height properties for seamless styling management

How can I save the font size and line height in a Sass variable, like so: $font-normal: 14px/21px; When using this declaration, I notice that a division occurs as explained in the Sass documentation. Is there a way to prevent this division from happening ...

Tips on creating a stationary header that moves horizontally along with the content:

Check out this website: The website has a fixed header that works fine, but when the window width is reduced or viewed on a mobile device and zoomed in, only the content scrolls horizontally. Is there a way to make the header stay fixed along the Y axis? ...

Can I restrict the translation of the educational institution's name on my website into a different language?

As I develop a website for a training facility, I have encountered an issue with the translated versions of the site. The training center's name is in English, and when the site is translated into another language, it alters the appearance of the name ...

"Implementing VueX 4 within a Nuxt 3 project: A step-by-step guide

As a newcomer to Vue, I initially began my project in Vue 3. However, upon realizing the importance of SEO optimization, I decided to transition to Nuxt. While attempting to move my application to Nuxt, I encountered some challenges. Despite reading that N ...

JavaScript Function Not Executed in Bottom Section

I've implemented AngularJS includes in my project. Below is the code snippet from my index.html: <!DOCTYPE html> <html ng-app=""> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> ...

Does Internet Explorer have a tool similar to Firebug for debugging websites?

Is there a tool similar to Firebug that is compatible with Internet Explorer? Edit I am currently using IE8, so I need a solution that works specifically with IE8. ...

Firefox inexplicably splits words in haphazard locations

Although I know about this question, the solution provided doesn't seem to work for me Firefox word-break breaks short words at random points Despite applying the recommended CSS property as shown in the screenshot, it appears that the latest versio ...

Place three images in the center of a div container

Recently, I've been working on some HTML code that utilizes the Angular Material library: <div layout="row" layout-wrap style="background: yellow; "> <div ng-repeat="pro in Products" > <md-card class="cardProduct" > ...

How can you split a row into 5 columns using Bootstrap 4?

Is there a way to divide a row into 5 columns in Bootstrap 4 with a total of 12 columns? Seeking some guidance here! ...