mini-css-extract-plugin: CSS files load order mismatch in prod and dev envs
I’m having the following issue:
In dev mode I have the following style order:
and in production it is like this:
Note different font-size
applied to the element because of different CSS specificity (files load order) in these cases.
.c101__sidebarLink
comes from react component that renders this element, and .plain-link, .contentful a
is from common.scss
that is imported in root component for the whole app.
My first assumption was that style-loader
and mini-css-extract-plugin
work differently because I’m using this config from the docs:
{
loader:
options.mode === 'development'
? 'style-loader'
: MiniCssExtractPlugin.loader,
},
But when I removed style-loader
and left only mini-css-extract-plugin
for both environments (just for testing purposes), the issue persisted. Then I used style-loader
for both envs and the issue was gone. Also I didn’t have this issue with webpack 3 and extract-text-webpack-plugin
for prod env.
So my conclusion is that the issue is in mini-css-extract-plugin
. For some reason it doesn’t persist order of loaded CSS files in different environments. I’m not sure if it is related to https://github.com/webpack-contrib/mini-css-extract-plugin/pull/130 because I don’t have multiple entry points.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 36
- Comments: 34 (11 by maintainers)
Commits related to this issue
- fix css files load order mismatch #188 — committed to ShanaMaid/mini-css-extract-plugin by deleted user 6 years ago
- fix css files load order mismatch #188 — committed to ShanaMaid/mini-css-extract-plugin by ShanaMaid 6 years ago
- test: loading order (#236) * fix css files load order mismatch #188 * fix(src): fix sort bug * feat(test): add test * test(sorting): add test case which uses the fallback behavior * fix(s... — committed to webpack-contrib/mini-css-extract-plugin by ShanaMaid 6 years ago
- Ensure application CSS has priority over library CSS Import our application CSS as the very last thing, so that it can properly override PatternFly variables. Before, our application CSS could land ... — committed to martinpitt/starter-kit by martinpitt 4 years ago
- Ensure application CSS has priority over library CSS Import our application CSS as the very last thing, so that it can properly override PatternFly variables. Before, our application CSS could lan... — committed to cockpit-project/starter-kit by martinpitt 4 years ago
Please stop writing post like
same issue
/same problem
, if you need help please create minimum reproducible test repoI have created a repo to demonstrate the CSS order difference between dev and prod builds. The problem isn’t related with multi-entry builds.
https://github.com/boraturant/MiniCssExtractPlugin_CSSOrderProblem
Any solution for this? Happen the same in my project…
@yantakus please reopen this issue
this issue should not be closed
#246 But CSS Ordering is still not 💯 deterministic and likely never will be, you will get spammy warnings in case chunk1 and chunk2 imports modules in a different order, otherwise css-modules usage is encouraged to avoid issues wit ordering (e.g the CSS Cascade) altogether
I can’t offer a minimum repo, but a repo where this problem occurs (well i think at least): https://github.com/ptandler/vuepress-theme-single-page-sections you can compare the screenshots on this page I generated from the dev server with the live version at https://ptandler.github.io/vuepress-theme-single-page-sections/ which runs the build. (using @vuepress/core@^1.2.0)
See also https://stackoverflow.com/questions/58977014/how-can-i-disable-the-mini-css-extract-plugin-in-vuepress
I noticed that VuePress uses mini-css-extract-plugin@0.6.0 so I tried upgrading mini-css-extract-plugin to the current version 0.8.0, but this didn’t change anything.
@evilebottnawi I try to fix this issue,it seems to be that
sort
func is not correct. I test pr #236 in local, issue is sloved.The same problem… I temporarily had to abandon any components (import css files inside js) Instead, I only import component files into my js entry. and in main.scss I import only scss components files. That is, while this problem is relevant, I cannot use webpack plugins to process scss / css and have to make the add-in a separate process (via node-sass) I don’t know why there are so few people who would notice this problem and start writing about it to the developers … Because for me this problem is just a critical … She put my development at risk, there was no time for a decision or for a search …
I recently experienced this problem occur by upgrading from 0.4.0 to 0.4.1.
Unfortunately due to rolling back and not having time I won’t be able to chase down the exact issue and provide a minimal replication.
I’ve experience drift between dev and production styles in the past due to changes in the ordering in which they are included which is understandable (I don’t use mini-css-extract-plugin in dev), however 0.4.1 changing means I will have to go back and re-check all dev/prod drift.
@boraturant it still works the same as described in my first message here. But I wasn’t able to reproduce it, when I removed 99% of the app and left just one page and a single component for demonstration purpose. In this case it works as expected, identically in prod and dev.
So I just used
!important
as a temporary workaround. If you manage to create a minimal reproducible test repo, guys here might be able to help us.