From 67797958b44103e42c62a2d7e0b1ad795eb1004a Mon Sep 17 00:00:00 2001 From: Vatsal Joshi Date: Wed, 11 Dec 2019 16:21:26 +0530 Subject: [PATCH] use MiniCssExtractPlugin with hmr in dev mode Remove style-loader --- .../react-scripts/config/webpack.config.js | 34 ++++++++++--------- packages/react-scripts/package.json | 1 - 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index bad4290061b..65c1745e614 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -92,10 +92,12 @@ module.exports = function(webpackEnv) { // common function to get style loaders const getStyleLoaders = (cssOptions, preProcessor) => { const loaders = [ - isEnvDevelopment && require.resolve('style-loader'), - isEnvProduction && { + { loader: MiniCssExtractPlugin.loader, - options: shouldUseRelativeAssetPaths ? { publicPath: '../../' } : {}, + options: { + hmr: isEnvDevelopment, + publicPath: shouldUseRelativeAssetPaths ? '../../' : undefined, + }, }, { loader: require.resolve('css-loader'), @@ -270,8 +272,8 @@ module.exports = function(webpackEnv) { : false, }, cssProcessorPluginOptions: { - preset: ['default', { minifyFontValues: { removeQuotes: false } }] - } + preset: ['default', { minifyFontValues: { removeQuotes: false } }], + }, }), ], // Automatically split vendor and commons @@ -493,10 +495,7 @@ module.exports = function(webpackEnv) { }, // "postcss" loader applies autoprefixer to our CSS. // "css" loader resolves paths in CSS and adds assets as dependencies. - // "style" loader turns CSS into JS modules that inject