Steps to avoid NuxtJS from merging all CSS files

Currently, I am working on a NuxtJS website that consists of two main pages: index.vue and blog.vue. Each page has its own external CSS file located in the assets directory, named after the respective vue file (index.css and blog.css). However, during testing using the dev command, I noticed that the styles from blog.css were overriding the styles from index.css, even though only the index.vue file was importing index.css. An example of this conflict can be seen with unordered list styles - index.css sets it to list-style-type: none;, while blog.css sets it to list-style-type: circle;

Related code:

index.vue

<script>
  import "~/assets/css/index.css";
</script>

index.css

ul {
  list-style-type: none;
}

blog.vue

<script>
  import "../assets/css/blog.css";
</script>

<template>
  <main>
    <ContentDoc />
  </main>
</template>

blog.css

ul {
  list-style-type: circle;
}

I have attempted different solutions such as using the in-built tags, utilizing the /public directory instead of /assets, and adjusting the webpack option extractCSS to see if anything changed.

Edit: After looking into the Vite build conditions and experimenting with Vite's build.cssCodeSplit set to both true and false, unfortunately, the issue remains unresolved.

Further investigation revealed that when I reload the index page, initially, only the expected css file is loaded. However, within milliseconds, the blog css file is also loaded, causing conflicts in the style editor where blog.vue appears alongside index.vue, index.css, Main.vue, FrameBox.vue, and Overlay.vue.

A temporary fix was found by hiding the blog.vue file in the Firefox style editor. Is there a way to replicate this behavior in the code?

Answer №1

How would you feel about trying this out:

<style lang="css" scoped>
  import "@/assets/css/blog.css";
</script>

As for the index.vue file:

<style lang="css" scoped>
  import "@/assets/css/index.css";
</script>

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

How can dataTables in VueJS be reloaded following an addition or edit?

I'm interested in implementing a similar approach for loading data from a database via an API. Initially, the dataTables load successfully. However, when a new record is added, I need to reload the dataTables to display the new record. Below is the HT ...

After filling out the form, the user's entered information is instantly shown on the same page

I want to create a form where my friend can input information that will be displayed on the same page. For example, when he enters the title in a text field and clicks submit, it should appear in the title box. Additionally, he should be able to enter va ...

Issue found within triggered hook: "TypeError: Unable to retrieve property '$http' as it is undefined"

Hey there, I've created a userInfo() function to fetch user data and utilize it in different areas. How can I effectively call this function to retrieve the necessary information? Can anyone assist me with this issue? export function getUserInfo () { ...

Refresh the Vue page only once after it is mounted

Users should only experience the page refreshing once upon visiting. However, if I add location.reload() within the mounted() function, it causes an infinite loop of page reloads. ...

Achieve vertical center alignment of items using flexbox styling

I'm attempting to vertically center elements using CSS flexbox. I have successfully implemented it with the non-vendor-prefixed code, but I am facing issues in Webkit (Chrome) even with the vendor prefixes. My goal is to vertically align the spans wi ...

The art of Vue JS displaying content

Learning how to make API requests using axios has greatly improved my ability to retrieve data in a client-side container and display it in my component template. It's been quite effective so far. Having worked with twig before, I can't help ...

Ways to display a specific HTML element or tag depending on the given prop in VueJs

When working with Vue.js, it's important to remember that a <template> can only have one root element. But what should be done if you need to render different html elements based on a prop? For instance, let's say we have a <heading> ...

Overlap of columns within a nested flexbox arrangement

While working with React and Styled Components, I encountered a problem of elements overlapping each other: https://i.stack.imgur.com/RuCYu.png There are a few instances of overlap, including: The padding below the <ul> element is colliding with ...

What causes the container's height to remain unchanged despite changes in the height of its image content?

When I set the height of an image to 50%, its container's height remains the same instead of automatically adjusting. HTML: <section class="img-show"> <div class="img-container"> <ul> <li cla ...

What is the best way to include documentation for custom components using jsDoc?

Within my Vuejs inline template components, we typically register the component in a javascript file and define its template in html. An example of such a component is shown below: Vue.component('compare-benefits', { data() { // By return ...

What could be causing my CSS transitions to fail when using jQuery to add classes?

I'm currently working on a website and I'm facing an issue with the transition not functioning as expected. The problem persists even when the 7.css stylesheet is removed and interestingly, the transition works fine when using window:hover. My a ...

Struggling to pass data changes between child components in Vuejs2?

Encountering a challenge with my current project. I have implemented a vuejs2 parent-child structure as outlined below Parent app child product-list product product-image colour-select In the product template, I initialize the sibling components ...

Understanding the use of "el" in a function parameter in Vue Js

I am new to VueJS, so please be patient with me. I am trying to code a function that will scroll to an element with a specific ID when a "?" is used in the URL. I want it to have the same effect as demonstrated here. My assignment requires me to follow a ...

The Date validation script in Javascript is malfunctioning

I encountered an issue where the script I used in my HTML file didn't work as expected. The purpose of this script was to prevent users from submitting a date greater than today's date. Interestingly, when I copied the same script to another HTML ...

Tips on updating the color of the drawer component's background in Material-UI using React

I have been attempting to change the background color of a drawer component in React, but I have only been successful in changing the background behind the drawer or the field with the items. Here is the code I am using: const useStyles = makeStyles({ ...

The Vuejs Fetch GET Request encounters a failure, despite working flawlessly in Postman and the browser, all thanks to a 302 redirection

In my web application developed with NuxtJS/Vuejs, I have a field where users can input a URL. The application is supposed to make a GET request to that URL and retrieve data, often related to GitHub in either XML or JSON format. However, when I try to pr ...

When refreshing the page, the authentication token set in the Vuex store using axios in Nuxt.js/Vue.js gets reset

Here is the code snippet I am using to manage login, logout, user retrieval, and token setting for all axios requests as an auth header. While this code works perfectly during client-side rendering - such as logging in, storing the token in cookies, etc. ...

Encountering issues with integrating Sass into Angular 4

Hi there! I recently started a new project in Angular 4 and encountered some issues with the Sass styling. Every time I try to add sass and run the project, I keep getting this error message: body{ h1{ color : red; } } ^ Invalid ...

What methods can I implement to ensure a button illuminates only when correct information is provided?

I have developed a calculator for permutations and combinations. When either permutation or combination is selected, and the required values are entered, I want the calculate button to light up. How can I achieve this without using setInterval in my curren ...

Vue - Struggling to send props to dynamically imported Web Components

Long time no see, old friend. I am navigating to a Vue file that is asynchronously imported (via import) upon routing. The template for this file is shown below, mainly serving as a way to load in a heavier web component and create separation from that co ...