I am new to that webpack thing and following some tutorials to learn basics.
I would like to use style-loader
to inject stylesheets during development (with HMR enabled) and want to use MiniCssExtractPlugin
for production builds. But when I use MiniCssExtractPlugin plugin, I loose injecting feature of style-loader.
Please see my webpack config :
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
module.exports = {
entry: ['./src/index.js'],
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.(sass|scss)$/,
use: [
"style-loader",
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development'
}
},
"css-loader",
"sass-loader"
]
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
})
],
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
hot: true,
port: 3000
}
};
style-loader
indev mode
&MiniCssExtractPlugin
inprod mode
. Your requirement is not clear. Kindly clarify – Ellette