New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS resolving order #215
Comments
It's loaded in the order you call the requires |
It's not happening on my case, any reason? I define this: require('se7en-bootstrap-3/build/stylesheets/bootstrap.min.css')
require('./stf-styles.css') But they get compiled in this order:
|
The order in the bundle is not the order they are added to the DOM. The oder in the bundle depends on the module id. And the module id depends on how often the id is used and alphabetical order. Or is random in dev mode. |
I see. |
|
This is strange, putting breakpoints shows them loading in the correct order. Can I specify a css as a dependency of another css? |
closing because it's old |
+1 |
This still happens. What's the workaround? |
@luisrudge Check if you have the lastest version of webpack, extract-text-webpack-plugin and css-loader. This shouldn't happen. |
I have, but it still happens. |
I have observed this issue using both a legacy and (at the time of writing) most up-to-date webpack and loaders. It appears to only happen on on rebuilds, however. For example, this works as expected:
But if I comment out the 2nd line, save, wait for rebuild, uncomment, save, wait for rebuild, the order of the file content in the output is reversed. I am splitting code with the CommonChunksPlugin but haven't explored if that matters. |
My workaround is to have an entry point for each "module" that has SASS dependencies.
|
I'm seeing a very similar issue. Going to try the entry hack that @raypatterson is trying too. |
I have this issue only if I use the extract-text-webpack-plugin. |
@timaschew Have you tried the latest versions for css-loader extract-text-webpack-plugin and webpack? They should have the correct css order. |
I've updated now from css-loader 0.14.5 to 0.15.1, the extract plugin is up to date at 0.8.2 It's normalize.css which is almost at the end of the css file. |
I can reproduce the issue in this repo: https://github.com/timaschew/webpack-amd-commonJs-demo |
I've started to debug the issue But there is an getOrder function which is comparing against the Then I printed out the both items which are compared
and
So, okay the order function is working, but why the values for If I add some logs between these lines and combine some others from the css-loader and extract-plugin I get this:
At this point it's too complex for me ^^ btw: I tried this with the new version of webpack: 1.9.12 |
Having the same problem as @timaschew and @vn38minhtran |
+1 |
any thouhgts on this? |
@luisrudge @Coobaha I just bumped my installed webpack version to 1.11.0 and css-loader to 0.15.6 and I started getting the correct import order, so this may be fixed. |
this caused incorrect order of rules in extracted css expose index and index2 to the stats
I'll try that |
Still doesn't work for me :( |
@x-yuri sry, what solution I've missed? |
@vladimir-kondratenko The issue is that there doesn't seem to be an issue. Can you please help us with reproducing it? Do you not see a way to affect the order of CSS files? Or you have a better idea of how it's supposed to work? |
@x-yuri I also probably missing the same as @vladimir-kondratenko . I switched off ExtractTextWebpackPlugin and now order is correct, but with that plugin order is incorrect. I am using wepack v3. Could u tell me how to resolve issue with extract text plugin? |
@egemon Sure, if you give me a way to reproduce it (repository or archive with the files needed to reproduce the issue). |
This is insanity this is still a thing. Also:
While this seems to be true, it is very puzzling why it's the case. What good is a development environment if it doesn't even seek to emulate a production one? And worse, you have to find a four year old comment to even know. |
@thomashibbard I admit that webpack is no simple piece of software, but I'd say the order is more or less obvious or expected, granted you have an idea how webpack works. From the first page of the documentation:
You don't tell weback about the order in any way, so dependency graph basically determines the order.
The order must not change from one environment to another. Can you help to reproduce it? Also, if you don't like its idea of order, what's yours? How would you like it to work? |
Hello. I looked at your repository and it seems you are importing them inside a js file. Im not sure if that`s why its working for you, but for me its like this - I have app.scss file with -
And bootstrap seems to be added after bootstrap-social. Maybe this helps you to figure this out? Im using laravel-mix. I understand that adds another element in the equation, but as I dont know much about the workings of webpack, this is what I use to make it easy. |
The main problem with css order - css is not deterministic. Example: @import 'foo.css';
@import 'bar.css';
@import 'bar.css';
@import 'foo.css';
@import 'A.js';
@import 'B.js'; When we extract css, who should be first? |
@evilebottnawi from my point of view it would be great to have a flag to make that error out and force the same order everywhere, since if there's any shared css in those files, A and B will have different outputs |
@CoolGoose we already do warning in mini-css-extract-plugin, do you have other case where you have invalid order and no warnings? |
@evilebottnawi I wouldn't call that nondeterministic. I believe nondeterministic is when output changes when input doesn't. What we have in the example though is contradicting demands. I take it the resulting order is determined by the first time a file was required. And a warning is given when css files are required in different orders. Which means... case closed, no? :) I'd like to check the last suggested case, but it's unlikely we'll learn anything new. |
@x-yuri we can have more difficult cases, so need good algorithm for this, maybe with options about preferences and controlling (this should be implemented in |
I don't know if it could be an important point but: is webpack's dependency graph created synchronously or asynchronously? |
It's 2020 and people (like @Abhi0725) are still asking those kind of questions? Instead of putting effort. Like, reporting his/her specific case and telling what he/she expects @evilebottnawi So you believe there are still cases where |
@alexanderharwood (hopefully I guessed the username right) The behavior you're describing is not correct. Can you please create a test repository that I can |
+1 |
This might help
In my case this was my issue. I mixed |
Yeah, but don't do that manually. Instead, use some tool like this: https://github.com/ggascoigne/prettier-plugin-import-sort |
Does the tool allow exceptions? Like, sort alphabetically but |
7 years has been passed since this ticket was submitted and the issue still exists. The solution what I found is to use third party plugins .scss files OR .css files only, do not use mix of them! In this case importing order is OK. But if I mix third party plugins' .css and .scss files, then .css files always goes first. |
We cannot guarantee CSS ordering between modules, because in some cases it is not possible, can you provide example the problem, I will say how to fix it/why you need to use other orders and say why it happens |
Dear Alexander, I've a very simple app.scss code:
in output, via mix, third-party styles goes first after compilation. If sample is *.scss , then it's ok but sometimes such files are not provided. What would be the way out in this case? |
It is not webpack problem, try to compile scss without webpack, |
Dear @alexander-akait thanks anyway, thanks for your time. try to play around. |
No webpack issue here, you have: @import '~bootstrap/scss/bootstrap';
@import '~third-party/sample.min.css'; after sass ( @import '~third-party/sample.min.css';
// Just example of code
.bootstrap-classes { color: red; } After // Just example of code
.bootstrap-classes { color: blue; }
// Just example of code
.bootstrap-classes { color: red; } This is misleading, but in fact this is how sass works. |
In my case the styles in bootstrap.css was always at top of my custom styles scss. |
I think we can close it, if somebody have problems with order, please open an issue in https://github.com/webpack-contrib/css-loader with example of the problem, currently most of the problems are solved |
If you're seeing out-of-order CSS in production mode inside node_modules, head over here: #7094 I brought a repro! |
Hi!
I have two files
where the file
bootstrap.css
needs to be loaded before./myfile.css
.Is there any way to do set the CSS resolving order properly in webpack for CSS?
The text was updated successfully, but these errors were encountered: