nuxt: Inconsistent css in dev vs prod
Version
Reproduction link
https://github.com/adi-zz/nuxt-css-dev-vs-prod
Steps to reproduce
- git clone https://github.com/adi-zz/nuxt-css-dev-vs-prod
- cd nuxt-css-dev-vs-prod
- npm i
- npm run dev
- npm run build && npm run start
- open http://localhost:3000/
What is expected ?
The background color of nuxt logo should be blue in both cases 3.1. and 3.2. (or at least red in both cases).
What is actually happening?
Background is blue in dev mode (3.1.), and red in prod mode (3.2.)
Additional comments?
My project was generated using npx create-nuxt-app test (choosing all defaults)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 12
- Comments: 26 (5 by maintainers)
The fix for me is to add
ignoreOrder: falseto extractCSS config.Hope it will help someone.
@clarkdo yeah, I also understand that, but you know, people been controlling css priority by defining specific order for years and practically getting rid of this habit will mean rewriting thousands of already existing css selectors whereas just switching the file order will fix it in a finger snap (you don’t even need to be a Thanos to do that)
And it happening again for “nuxt”: “^2.7.1” In the inspector window, I see that styles have a different order. The application was generated using
npx create-nuxt-app testwith vuetify ui. And I see that_grid.stylappears after_lists.stylin dev and vice versa in prod. Could this ticket be reopened? Or I need to create new one?Need to find a way to guarantee ordering, without resorting to making a master CSS/SCSS file that imports all 3rd party libraries + custom style overrides
@clarkdo this is understandable, but sometimes there are use cases when using scoped styles is not an option. e.g. consider a project that was created on top of a vanilla html/css template without any view components to start with, so all those styles are separate scss files bundled in a one big global css chunk that should properly interact with style libraries such as bootstrap that are also connected to the project.
@manniL please, reopen! extractCSS is so buggy that I actually gave up on it, it was easier to reduce styles by 10 times than to fix all issues that keep happening with this property 🤦♂️
Based on my experience, there are 2 reasons that i know of that makes the css of the built version not consistent with the dev version.
@AndrewBogdanovTSS 😸
I understand and I didn’t mean that we must use
scopedhere.Since the injection of css files is asynchronous, so the order of css files are not guaranteed, the root problem is more related to the way how we should organize css.
My point is that it’s not a proper way to prioritize styles depending on the order of selector location in file.
If we want make a selector prior to another, we should use higher priority selector:
@adi-zz A good advice is that do not depend on the insertion order to write styles: https://github.com/vuejs/vue-loader/issues/938#issuecomment-338279776
It will be correct as your expectation if you add
scopedinindex.vue: