Open ziacik opened 1 year ago
Hello. I have a similar issue, but I am importing the scss file inside by global styles.scss endpoint that has references to the local font files. If I remove the PostcssCliResources plugin, everything works perfectly. There was already a Pull Request 14616 where that plugin was disabled for the CSS module. But it looks like the fix should be more profound.
@leosvelperez can you tell me the purpose of the PostcssCliResources plugin just out of curiosity? I did not find the comments in your repository regarding it.
Yeah, I face a similar issue. After days of struggling, I finally found the cause of the problem.
the PostcssCliResources will always emit the file, is there any one can tell me why we do that?
Current Behavior
Hi. Once again I'm going to report this, since I still believe the implementation of image processing in the css files is not correct in @nx/webpack.
I would expect, that stuff like this:
would let webpack's asset processor to process the image, and depending on the image asset settings, it would inline the image if possible.
Current default setting for image processing is "asset" with a dataUrlCondition of maxSize: 10000, so the small enough image should be inlined.
But it isn't.
Expected Behavior
Image asset rule should be respected in url() references of styles.
So with default setting, an image < 10000 should be inlined.
GitHub Repo
https://github.com/ziacik/nx-bug-1
Steps to Reproduce
(See my repo, build the main app
nx build
)Nx Report
Failure Logs
No response
Operating System
Additional Information
I tried to investigate and figured out that this is probably caused by hardcoded image processing via postcss specifically the nx's
PostcssCliResources
postcss plugin.Because of that, css-loader is configured with
{ url: false }
option which I believe disables processing of urls by css-loader which (as I found) doesn't have such problem with the images and leverages the webpack's asset image processing correctly.I don't know why this is configured like that. I don't know what else the PostCss loader does (is it documented? i don't think so). Looking at the PostcssCliResources plugin, it uses webpack to emit files, but they don't seem to be further processed by webpack (is this the bug? maybe it should be emitted some other way? i don't know, i'm no expert on webpack).
I can have a workaround by removing the css rules configured by
withWeb()
and adding something like this back:With this, the inlining works as expected. But as I said, I don't know what the postcss-loader does and whether I should use it or what. (See in my repo when you uncomment the
rules:
line).I'd be happy if there was less messing with standard ways of webpack configuration so that I can know what to expect. Or at least if the stuff was documented and configurable in such a way that workarounds are not needed, especially when the workaround means inspecting current configuration of rules, finding the correct rules and "subrules", splicing and replacing and hoping it won't break with the next nx version upgrade (as happened to me).
Anyway, besides the criticism, I still thank you for the work you do on this.