-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
feat: onEmit configuration option #322
base: master
Are you sure you want to change the base?
Conversation
Should be done on webpack level, not on plugin |
Please provide repo with use case and describe in README what you have and what you expected |
I can extract all the code we're using with this into a standalone repo, but it would be a lot of work; is the description of our use case not clear? I'm not sure how I could do this at the webpack level without just forking the plugin, which I'm trying to avoid. The order of CSS assets produced by mini-css-extract-plugin is not deterministic over time, as things are added and removed, which can create instability because of CSS conflicts. So we capture the order of assets and add them to a lock file when they're first seen. On future builds, new assets are inserted in to the lock file using an algorithm that determines the best place without altering the order of any existing assets. So on the first run, the lock file will match the order produced by mini-css-extract-plugin. On future runs, when a new asset is seen, we insert it into the lock file, but never change the order of existing assets in the lock file. (This is where the order will diverge from mini-css-extract-plugin, since nothing prevents future runs from producing CSS bundles in a different order with the current logic in the plugin). We then need to re-order the set to match the order of our lockfile. |
@jamietre I can't understand you. Why you need this, need repo to demonstrate problem. Some features out of scope this plugin, maybe better create own plugin for this rare use case |
I agree the specific problem/our solution is out of scope; that's why I only want to add a generic hook to empower users to add custom logic to the final order of assets produced by mini-css-extract-plugin. There are many issues related to this problem. Maybe this should just be another plugin in the pipeline after mini-css-extract-plugin? This seemed like a straightforward solution but perhaps there is a better ways to re-order the assets after they are output by mini-css-extract-plugin. |
I don't think you understand. This is not a bug, it will never be fixed because the behavior is expected. See:
This simply allows us to implement a solution to have deterministic CSS ordering in our app. There's probably no "right" answer for how to do this, and our implementation involves writing metadata (the lockfile) and some nontrivial logic, which is why it's out of scope for this plugin. I don't think allowing end-users to have a hook to implement their own solution to CSS ordering is out of scope; but if it's not going to be allowed I'll either fork it or find another way. |
Not sure it is truth, anyway if we need this it is should be as Why hard to create minimum reproducible test repo? Maybe you case it is bug and should be fixed without hacks. |
This problem only manifests when a lot of complex CSS dependencies are involved and certain changes are made and/or when splitting out chunks. We experience it in our repo (with hundreds of CSS modules) from time to time. I can't publish our proprietary source code, nor am I even sure what steps I would have to take to reproduce it, since it doesn't happen often, so creating a repro case would be very time consuming. I thought this was pretty well understood given the number of issues referencing non-deterministic CSS order, so apologies if that's not the case. But it would be a lot easier for me just to keep using the fork than to have to prove in an isolated repo that this problem exists. And again - I'm not trying to solve any particular problem here but just give people an option to re-order CSS for whatever reason they need to. If there's a better way that would be acceptable (I don't know what you mean by |
This is not the right solution. Maintaining the fork requires you extra time and cost. I do not need to prove the existence of a problem, I believe you. Why i need reproducible test repo? Because problem can't be located in plugin, maybe bug in chunks/modules order on I do not ask to show the source code of the project, although I have already signed DNA several times for finding and fixing problems, so this is also not a problem. Also as i write above we need |
Again, there's no bug that needs to be fixed; we just want a way to re-order the CSS. Spending hours trying to create a repo that reproduces a problem that seems to be well understood is not a good use of my time. I'd rather not use a fork, but the cost is low compared to continuing this debate and doing a bunch of work to prove a problem exists, which isn't even directly related to the change I want, and which may not even result in this PR being accepted. I'm not trying to push code that solves a particular problem so I don't see what bearing the repro of my particular need for this has, anyway. I'm just trying to give people a simple way to post-process the CSS that is produced to re-order it; there could be lots of applications for this. Again I don't know what a "hook" is but if you'll accept this using some alternative implementation I'm glad to revise. You need to point me to the correct way, that's all. Closing for now, if you change your mind let me know. |
Your communication violates the code of conduct, I get dozens of issues and PRs and I need time to understand the problem. I also need to discuss some aspects on implementation. It is normal for OSS. Unfortunately, your communication only indicates that I do not want to understand the problem and something to do with it, although this is not truth, so I have no desire to help you. How implement hook and use this in own plugin https://webpack.js.org/api/plugins/#custom-hooks. |
I'm really sorry; I've tried to be completely professional in my communications here. What did I say that violated the code of conduct? I appreciate that you do not understand the problem; all I'm saying is that it would be a lot of effort for me to complete the tasks that you've asked of me here, and it's simply not worth it to me, since the alternative of using our fork is pretty low cost. This changes rarely, it it's easy to maintain our fork since the change is so trivial. I hope you can appreciate that I have to make decisions on how to use my time; while I'd rather get a change merged here that would enable us to not use a fork, it doesn't seem worth the cost at this point. I also appreciate that as a repo maintainer you have requirements for what code you'll accept, and I have no hard feelings if you don't want to accept this without my doing what you've asked. Are we cool? |
@jamietre yep, anyway please look on implementation as custom hook to allow other people write own logic. I just want to see you logic in |
Setting up a hook doesn't look to hard. I'm glad to revise this to use a hook if that gives us a good chance of getting it merged. I thought about this some more and I realize I can demonstrate this issue in a pretty simple way. (This isn't actually exactly how it happens for us, since it's usually related to chunk splitting, but it's a contrived case) Suppose you have files: index1.js
index2:
index3.js:
The output will be ordered as: If you revise index1: index1.js
The output is now ordered as This is completely expected; but it's not acceptable for us, because css conflicts between "b" and "c" could change the way content renders. Instead, we maintain a lock file that fixes the order "a, b, c" when those assets were first seen, so changing index1.js as I did would still result in the order being "a, b, c". So of course ideally we wouldn't have CSS that conflicts in ways like this, but we have hundreds and hundreds of CSS modules and situations where specificity can alter the outcome. It's proved impossible to ensure it's all correct over time especially with shared code. This ensures that we don't have surprises. |
@jamietre thanks for the explanation, before answer i want to looks how other bundlers ( Also i think |
This kind of conflict is pretty common when shared code is involved; if I have some small React component that's used in a lot of places, the position of it's CSS will depend entirely on when the first consumer is loaded. In a big application, that can easily change frequently. I'm not sure it should result in a warning, it's just the way we resolve CSS -- it goes in order of the first consumer. But we just want to make sure that order doesn't change once established.
I'm glad to solve this in whatever the easiest/most sensible way is. It's not obvious to me how I can change this after |
Tomorrow I will evaluate all the possibilities and solutions and answer you, thanks for the feedback. Feel free to feedback and pinging me 👍 |
Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #322 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 3 3
Lines 284 288 +4
Branches 59 61 +2
======================================
- Misses 234 236 +2
- Partials 50 52 +2
Continue to review full report at Codecov.
|
This PR contains a:
Motivation / Use-Case
We need to lock the order that CSS appears in assets produced by mini-css-extract-plugin over time. We've implemented this my maintaining a lock file that persists the order of CSS modules when they are first seen, but this requires post-processing of the final list produced by the plugin to enforce the order when the bundles are built.
This pull request adds a hook so consumers can optionally post-process the final set of "used modules" before they are returned to webpack.
Breaking Changes
None
Additional Info
None