Struggling to set up Tailwind in NuxtJS configuration

Using the "@nuxtjs/tailwindcss": "^2.0.0" for my Nuxt App has been quite helpful. Upon installation, it generated a tailwind.config.js file. I made some modifications to the code below:

module.exports = {
      theme: {},
      variants: {},
      plugins: [],
      purge: {
        enabled: process.env.NODE_ENV === 'production',
        content: [
          'components/**/*.vue',
          'layouts/**/*.vue',
          'pages/**/*.vue',
          'plugins/**/*.js',
          'nuxt.config.js',
        ],
      },
      options: {
        important: true,
      },
    };
    

Despite setting all Tailwind classes as important in the configuration, they did not behave as expected.

View an example of one such class

Where did I go wrong?

Answer №1

It appears that your environment is set to NODE_ENV=production, which is why unused classes are being purged.

If you want to prevent this behavior, you can set purge.enabled=false. However, it's not recommended as purge helps remove unused classes from the HTML.

module.exports = {
  theme: {},
  variants: {},
  plugins: [],
  purge: {
    enabled: false, // AVOID SETTING THIS TO FALSE IN PRODUCTION
    content: [
      'components/**/*.vue',
      'layouts/**/*.vue',
      'pages/**/*.vue',
      'plugins/**/*.js',
      'nuxt.config.js',
    ],
  },
  options: {
    important: true,
  },
};

Answer №2

According to the documentation, the crucial key should be placed at the top level of the export object:

// tailwind.config.js
module.exports = {
  essential: true,
}

Rather than being nested within an 'options' key like this:

// tailwind.config.js
module.exports = {
  options: {
    essential: true,
  }
}

Answer №3

It became clear to me what was causing the issue.

Turns out, the culprit was related to PostCSS

Additionally, in previous versions, the important setting was within the options, but now it is located at the root level

// tailwind.config.js
module.exports = {
  important: true,
}

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

Add an item with a combination of different data types (such as objects and arrays) to a Mongo database, but encountering

I am currently working on posting an item to MongoDB using a combination of Node.js, Express, Mongoose, and Vue.js. The item I am trying to post consists of a mix of objects and arrays. Although the object post is successful in generating an ID, the data i ...

I keep encountering the same issue every time I try to execute the npm run watch command. Does anyone have any suggestions on how to fix this?

When attempting to execute the command npm run watch, I encountered an error as shown below: ERROR Failed to compile with 1 errors2:50:28 PM This dependency was not found: * vue in ./resources/js/app.js To install it, you can run: npm install --save vue ...

The event in Vue.js does not trigger for items that have been filtered out of the list

I currently have a list of items, each with a "complete" flag. Depending on the value of this flag, the item is displayed in either view A or view B. These items are fetched through an API request and then filtered client-side using a computed method based ...

The 'default' export is not found in the 'tailwind.config.js' file

Is it possible to utilize a theme variable for Tailwind within the Nuxt code for Storybook? Although everything appears to be fine during development, I encounter an error when building Storybook stating that ""default" is not exported by "t ...

Leveraging Vue.js's computed properties to access and manipulate elements within an

I have a simple template that displays text from a wysiwyg editor using two-way data binding, as shown below: <template> <div> <quill-editor v-model="debounceText" :options="editorOptionProTemplate" > </qu ...

Utilize separate v-for directives in Vue 3 for a single component

Within my JobComponent.vue file, I am fetching data from a VUEX Store. This component is utilized on two different pages - the first being Home.vue and the second being AllJobs.vue. When used in AllJobs.vue, JobComponent.vue works perfectly fine as it rend ...

The "open" property was called upon during the rendering process but is not present on the current instance

In my Laravel-Vue application, I have noticed the following: @include('header') <div id="app"> @yield('content') </div> @include('footer') Everything seems to be working fine with this setup. Howev ...

Calculating the sum in a VueJS pivot table

Currently, I am delving into VueJS and working on migrating a basic application from Laravel with the blade template engine. The backend remains unchanged, consisting of a straightforward RESTful API with 3 tables: Books, Places, and a pivot table named B ...

What is the best method for saving Vue's `prototype.$something` in a distinct file?

Is there a way to declare Vue.prototype.$myVariable in a separate file without cluttering the main.js? ...

Mastering VueTify: Customizing CSS like a Pro

Is there a way to modify the CSS of a child vuetify component? .filterOPV > div > div { min-height: 30px !important; } .filterOPV > div > div > div { background: #f5f5f5 !important; } <v-flex md2 class="filterOPV&quo ...

The background image on Nuxt.js is not adapting to different screen sizes

My journey with developing a Nuxt app hit a snag in the CSS department early on. The issue plaguing me, as is often the case, is responsive background images. Everything looked great during testing on desktop browsers, but when I opened it up on my mobile ...

When IntelliJ starts Spring boot, resources folder assets are not served

I'm following a tutorial similar to this one. The setup involves a pom file that manages two modules, the frontend module and the backend module. Tools being used: IDE: Intellij, spring-boot, Vue.js I initialized the frontent module using vue init w ...

Begin fetching data asynchronously in Vue Nuxt to initialize data

I'm working on a Vue-Nuxt component and I need to set the initial value of a data property in my component using data retrieved from an asyncData API call. data () { return { selected_company: this.contracts.company1.id *--> this gives me an ...

Vue3's transition behavior sets it apart from Vue2. It introduces new functionalities when managing templates outside of the transition

I recently made the leap from Vue2 to Vue3, but I'm encountering some challenges with the transition behavior. Here is the original Vue2 code: https://codesandbox.io/p/sandbox/silent-surf-yth66k?file=%2Fsrc%2FApp.vue <template> <div id=&q ...

"Exploring the world of Vue.js and videojs: refreshing the video

Is there a way to refresh the videojs in Vue (3)? Here is the code snippet I am currently using: <template> <video-js controls="true" preload="auto" ref="video_player" class="video-js vjs-big-play-centered&quo ...

Utilizing Vue.js 2.x to send a REST API request with a collection of objects

I currently have an array of objects stored in state, and my goal is to send this entire structure to a back end API for processing and receive a new set of values in return. Below is a simplified representation of this structure as viewed in the develope ...

Can you target an 'input' field that is within a component conditionally rendered using 'v-if'?

Imagine this vue.js template code: <div v-if="y===0"> <input ref="textbox">{{textbox}}</input> </div> In the scenario where y is data retrieved asynchronously, Is there a way to direct focus to the 'input' element onc ...

Develop a straightforward static webpage and set it up by installing and launching it using NPM

I am attempting to craft a straightforward HTML page that incorporates CSS/JS and utilizes npm. The objective is to construct a basic page that can be accessed by simply using "npm install" and "npm start". As an example, I will design a page with HTML, ...

What is the best way to populate a Vue form with pre-existing data?

Currently, I am utilizing Vue form to edit a single item. However, I am struggling to determine the correct method for assigning values to categoryName and description in order to display those values within the form. I have attempted to retrieve the valu ...

organize column and row indexes in vuejs by descending order

I have created a table with rows and columns. Right now, the cell located at (1,1) is in the top-left corner of the table. Is there a way to change it so that the count starts from the bottom left instead? This is the code I am currently using: <tabl ...