Managing the Loading Sequence of CSS Files in Nuxt and Vuetify

I am facing an issue in my Nuxt/Vuetify application where I cannot seem to load my custom CSS file after Vuetify's CSS. Despite attempting to change the order in the CSS array like so:

css: [
    '~/assets/style/main.scss',
    '~/assets/style/app.styl'
  ],

...I have had no success in getting my custom CSS to load after Vuetify's. This problem has also been discussed in a previous question on Stack Overflow, but it seems to remain unanswered, leading me to believe that the issue lies with Vuetify and has not been addressed by the creators.

Is there another explanation for this issue, or is there a possible solution that I am missing?

Answer №1

It's worth mentioning that Nuxt has been facing this issue for some time now, but there are several solutions available.

Option 1: The quick and dirty way...

To address the problem, you can remove the override CSS from your nuxt.config.js file (while keeping Vuetify) and instead place your override code within a style block in your default layout.

<style lang="sass">
  @import assets/style/main.scss
</style>

However, the downside of this method is that you will need to duplicate it for each new layout.

Option #2: The more elegant but potentially complex approach

Another way to tackle this issue is by creating an "all" CSS file and importing both your stylesheets into it. This method may be more complex as it might require compiling your stylus files into CSS before they can be imported. Nevertheless, assuming you are not modifying the Vuetify styles, this approach should work seamlessly.

all.scss (be sure to save it as .scss to ensure processing)

@import "app.styl";
@import "main.scss";

Import all your CSS files (in any desired order) into this single CSS file.

nuxt.config.js

css: [
    '~/assets/style/all.scss',
  ],

Answer №2

Still facing the issue in vuetify 2.2.19, nuxt 2.0.0, and @nuxt/vuetify. One workaround is to set extractCss: true in the nuxt.config.json file under the build section. However, this caused a hot module replacement (HMR) bug for me where styles weren't dynamically updated in the development environment, requiring a page reload after each style change.

In my case, the more effective solution was:

  1. Disable @nuxt/vuetify, completely remove the vuetify section, and eliminate '@nuxtjs/vuetify from buildModules.

  2. Ensure styles are loaded in the correct order in the styles section of nuxt.config.js. For me, without custom SASS variables in vuetify, it looks like:

css: [
  'vuetify/dist/vuetify.min.css',
  '@mdi/font/css/materialdesignicons.css',
  '~/assets/styles/main.scss'
]
  1. If you do use custom SASS variables, I recommend precompiling vuetify based on them in a separate build step and placing it in the static folder, as these variables typically don't change frequently.

  2. Manually include vuetify using the following plugin:

import Vue from 'vue'
import Vuetify from 'vuetify'
import en from 'vuetify/lib/locale/en'
import lt from 'vuetify/lib/locale/lt'
import pl from 'vuetify/lib/locale/pl'
import colors from '~/config/colors'

Vue.use(Vuetify)

export default ({ app }) => {
  app.vuetify = new Vuetify({
    lang: {
      locales: { en, lt, pl },
      current: 'en'
    },
    icons: {
      iconfont: 'mdi'
    },
    theme: {
      options: {
        customProperties: true
      },
      themes: {
        light: colors
      }
    }
  })
}

Answer №3

There appears to be an ongoing issue with Nuxt that has yet to be resolved. According to Vuetify, they do not believe the problem lies on their end: https://github.com/vuetifyjs/vuetify-loader/issues/23

Users have reported inconsistent CSS file loading problems with Nuxt version ^2.7.1. This issue has been discussed in detail here and here.

Efforts are being made to address this issue, as mentioned in this update. However, until a solution is officially released, it may be necessary to revert to a previous version to avoid these problems.

Answer №4

I've encountered a similar issue that I managed to resolve.

In my situation, I addressed it by removing all the CSS loading in the nuxt config:

css: [
    // ~/assets/style/app.styl,
    // ~/assets/style/custom.styl,
],

and transferring it to the plugins/vuetify.js file:

import Vue from 'vue'
import Vuetify from 'vuetify/lib'
import colors from 'vuetify/es5/util/colors'

import 'assets/style/app.styl'
import 'assets/style/custom.styl'

Vue.use(Vuetify)

As a result, I am now able to customize the default Vuetify theme, although it does prolong the compilation time when using Hot Module Replacement.

While it may not be the most optimal solution, I struggled to find a more efficient workaround.

Answer №5

Just wanted to share a solution in case it helps someone out there. I recently encountered an issue where a 3rd party library's css was not loading properly in a project built with NUXT. After seeking help on their support channel, a developer pinpointed that the problem stemmed from postcss.

To resolve this issue, we added the following code snippet to the nuxt.config.js file:

nuxt.config.js:
build: {
    postcss: false
}

Additionally, the issue was reported as a bug in NUXT and can be found here: Some CSS rules removed by PostCSS

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

Retrieve the value of the following object in a loop - Vue JS

I needed to verify whether a specific property of an object matches the property of the next object in an array of objects while looping through using a v-for loop. Here's an example JSON object: [ { Date: '21-July-2017', ...}, { Date: ...

Switching from Webpack-simple to Webpack in a Vue application: A step-by-step guide

I mistakenly created a vue application using webpack-simple, which I now realize is not suitable for deployment. Is there a way to switch to webpack without starting over with a new project? Thank you in advance. Edit: Below is the server.js code where I ...

Prevent Child Elements from Overstretching Container with Bootstrap Flex

I'm working on a layout where all elements can be viewed without the need for scrolling. Any panels that require more space should be scrollable. In the following example, I want the contents of main-left to be scrollable without stretching the entire ...

I am experiencing some unwanted movement of divs when I hide one element and show another. Is there a way to prevent this from happening

My webpage features a dynamic div that transforms into another div upon clicking a button. Although both divs share similar properties, clicking the button causes some elements to shift unexpectedly. Strangely enough, when the height of the replacing div i ...

Creating an adaptable CSS triangle for an image

Is there a way to create a responsive triangle on an image that resizes properly and stays aligned? I'm currently having issues with it becoming misaligned. How can this be resolved? .image { width: 100%; } .image ...

How can the parent div adjust its height to match the tallest child div?

Currently working on a web project where I have a div named "page", housing two other divs - one on the left called "navigation" and the one on the right named "content". I am aiming to set the height of the "page" div to match the height of the tallest di ...

During DragAndDropToObject in Selenium IDE, the initial element in the list is overlooked

I have a webpage that is split into two datagrids. The left datagrid is structured like this: <ul class="left_dg"> <li> <ul></ul> </li> <li> <ul></ul> </li> <li&g ...

The error message "The export named 'render' (which was imported as 'render') could not be found" appeared

Encountering an error when building a Vue project with TypeScript and Webpack, specifically the "export 'render' (imported as 'render') was not found" issue. Below is the full error code: export 'render' (imported as 'ren ...

Issues have been reported with Angular 10's router and anchorScrolling feature when used within a div that is positioned absolutely and has overflow set

I feel like I may be doing something incorrectly, but I can't quite pinpoint the issue. Any help or pointers would be greatly appreciated. My current setup involves Angular 10 and I have activated anchorScrolling in the app-routing.module file. const ...

Exploring CSS3 Border-Radius Compatibility with Internet Explorer 9

After creating a CSS3 gradient using ColorZilla, I noticed an issue with the DATA URI that seems to be causing problems. Check out my fiddle link here: http://jsfiddle.net/cY7Lp/. In WebKit & Firefox browsers, the rounded corners display correctly. Ho ...

Incorporating Vuetify into a Vue CLI application with the help of webpack

I am facing an issue with my Vue CLI application that uses Webpack and Vuetify. The Vuetify components are not loading properly, and I keep getting the following warnings: Unknown custom element: < v-app > - did you register the component correctly? ...

Implementing a dual-column design for MailChimp using HTML and CSS

I'm feeling overwhelmed. I have a MailChimp layout that I exported from MailChimp. Currently, the layout consists of 3 columns, but on mobile, it converts to 1 column. Here is the link to the codepen: goo.gl/Fj8Ct7 Is there anyone who can assist me ...

Can Antd's Typography.Paragraph be used as a multi-row Menu title?

I am having trouble getting multiple rows to work inside the Antd Submenu. When I select only one row, it works fine. However, when I try to select multiple rows, the ellipsis is not shown at all and the text remains in one row. <SubMenu ...

Outline of a Bootstrap row

I am trying to create a row layout where the background extends beyond the designated row area. The desired design is shown in the image, with an additional white space before the actual text of the row. However, when I attempt to start a new row and set ...

Enhancing the visual appeal of a standard jQuery slider with thumbnails

Recently, I incorporated the Basic jQuery slider into my website, which can be found at . As a novice in jQuery but well-versed in HTML and CSS, I have managed to make it work seamlessly on my site. However, I am curious to know if there is a way to displa ...

How to turn off a sticky header on Mobile using CSS

Below is the code I am using to create a fixed header on my website. <?php } ?> <header id="header" class="<?php if ( theme_option( THEME_OPTIONS, 'enable_header_fixed' ) == 'true' ) : ?> fixed_header <?php else : ?&g ...

Updating the title of a page on CoreUI's CBreadcrumbRouter dynamically

I'm currently developing a project with VueJS and the CoreUI admin template. Is there a way I can change the title of the current page as shown on the CBreadcrumbRouter? The GitHub documentation mentions that the script typically displays meta.label ...

Is there a way to connect a CSS external file that is saved on Dropbox?

Is it possible to link an external CSS file stored in Dropbox with HTML? I have followed all the instructions I could find online, including clicking and pressing "Copy Dropbox Link" to generate an href link. However, it doesn't seem to be working. ...

Identify the appearance of a web component being added to the Document Object

After reading this discussion regarding a web-component I created: <my-vue-web-comp [userId]="1" id="my-component"></my-vue-web-comp> The component functions properly in Angular. How can I determine when the web component h ...

Using Vue's computed property to display the current date

Is it possible to display today's date on the homepage of my website? I found it easy to achieve using vanilla JS, but with Vue.js, it seems more challenging. No matter what I try, I can't seem to get it working properly. Below is the code snippe ...