Skip to content

The order of <style> and <link rel="stylesheet"> changes after build #4890

@fango256

Description

@fango256

Hi, I've been struggling with an issue that causes our override CSS rules to fail on some builds. In our production app it is actually inconsistent - however the simple local reproduction repository i've linked to seems to reproduce consistently.

When using a single entrypoint the generated index.html correctly outputs vendor.css followed by the local css (index.css). However when i include a second entrypoint with exactly the same content as the first entrypoint the generated index.html files have the CSS defined in the wrong order in all entrypoints. The CSS is ordered correctly in Vite serve mode.

Using main.js

import { VApp } from "vuetify/lib";
console.log(VApp);

import '../style.css'

document.querySelector('#app').innerHTML = `
  <div class="v-application theme--light">I should have a blue background as my CSS is overridden in style.css</v-application>
`

With one entrypoint in correctly outputs:

...
<link rel="stylesheet" href="/assets/vendor.06e82a89.css">
<link rel="stylesheet" href="/assets/main.b16cdc1a.css">
...

But including a second entrypoint with the same js content flips the CSS ordering in both the output html files:
build/index.html

...
<link rel="stylesheet" href="/assets/style.0cc4c6eb.css">
<link rel="stylesheet" href="/assets/vendor.06e82a89.css">
...

build/entrypoint2/index.html

...
<link rel="stylesheet" href="/assets/style.0cc4c6eb.css">
<link rel="stylesheet" href="/assets/vendor.06e82a89.css">
...

Reproduction

https://github.com/fango256/vite-css-ordering-issue

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 40.92 GB / 63.92 GB
  Binaries:
    Node: 16.5.0 - C:\Program Files\nodejs\node.EXE
    npm: 7.19.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (93.0.961.38)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    vite: ^2.5.4 => 2.5.6

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions