Setting up CSS bundling in Webpack
The learned method of adding CSS to a page may not be very successful. It is often more convenient to collect all CSS files in a separate bundle with styles.
For this you need the plugin mini-css-extract-plugin. Let's install it:
npm install mini-css-extract-plugin --save-dev
Let's import it:
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
Let's add to the plugins
setting:
export default {
entry: './src/index.js',
plugins: [new MiniCssExtractPlugin()],
};
Now let's replace style-loader with the loader from our plugin:
export default {
entry: './src/index.js',
plugins: [new MiniCssExtractPlugin()],
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
};
Perform the settings described.