DEV Community

[Comment from a deleted post]
Collapse
 
ansimorph profile image
Björn Ganslandt

Is there a way to use this approach with css components?
When I try, style loader always fails with: ERROR in Template execution failed: ReferenceError: window is not defined.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
ansimorph profile image
Björn Ganslandt

I'll set up a minimal repo when I find time, but meanwhile I figured out what the problem is in case anyone trips over the same problem.

Style-loader expects a DOM, which isn't there yet in the context of HtmlWebpackPlugin rendering the pages:

github.com/webpack-contrib/style-l...

Minicssextract has the same issue:

github.com/webpack-contrib/mini-cs...

So this boils down to a SSR problem for which the mini-css-extract issue discusses some possible solutions.

I ended up going the conventional way and included the css in a js-entrypoint.