I have an ejected create-react-app (webpack version 3.8.1) that will be implemented as a third-party widget on other websites. The components are rendered in multiple iframes using react-frame-component.
When styling the components inside iframes I include the css in the head of the iframe. Right now I'm doing it by loading the css into a string like this:
// IframeComponentOne.js
const innerStyles = require("./iframe-component-one-styles.scss").toString();
render() {
return (
<Frame
head={<style>{innerStyles}</style>}
>
<CompA />
<CompB />
...
</Frame>
)
}
// IframeComponentTwo.js
const innerStyles = require("./iframe-component-two-styles.scss").toString();
render () {
return (
<Frame
head={<style>{innerStyles}</style>}
>
<CompC />
<CompD />
...
</Frame>
)
}
However, to minimize bundle size, and defer css loading, I would like to extract the css into separate files and link to them in the iframes like this:
render() {
return (
<Frame
head={<link rel="stylesheet" href="specific-frame.[hash].css">}
>
<CompX />
<CompY />
...
)
</Frame>
I'm aware that I probably need to use extract-text-webpack-plugin to extract the different innerStyles, but can't the webpack setup right.
How would a webpack setup for this look? How do I reference the extraced css bundles with content hashes in the head of the iframe components?