I have a simple multi-page app with three pages, my webpack.config.js
entry
looks like:
{
entry: {
a: 'pages/a.js',
b: 'pages/b.js',
c: 'pages/c.js',
}
}
Each page consists of several React components, some of which are visible above-the-fold on first render, and some of which are out of view.
I'd like to declaratively define which components are 'critical' (above-the-fold) for each page/entry, and have that CSS extracted into a separate file. Something like:
{
a: ['compononents/button/style.css', ...],
b: ['compononents/title/style.css', ...],
c: ['compononents/header/style.css', ...]
}
outputting something like:
- dist/a.critical.css
- dist/b.critical.css
- dist/c.critical.css
I've been playing around with the extract-text-webpack-plugin, but can't seem to find a way to tell it to only extract specific CSS in the context of a specific entry.
How can I extract specific CSS file content when in the context of a specific entry/page?