diff --git a/packages/crafty-preset-postcss/src/webpack-utils.js b/packages/crafty-preset-postcss/src/webpack-utils.js index 73a245e55..5c3f1ae1c 100644 --- a/packages/crafty-preset-postcss/src/webpack-utils.js +++ b/packages/crafty-preset-postcss/src/webpack-utils.js @@ -70,22 +70,20 @@ function getCssModuleLocalIdent(context, _, exportName, options) { ); } -function extractCss(bundle, chain, styleRule) { - // Add this only once per bundle - if (bundle.extractCSSConfigured) { - return; - } - bundle.extractCSSConfigured = true; - +function configureMiniCssExtractPlugin(bundle, chain) { // Initialize extraction plugin const MiniCssExtractPlugin = require("mini-css-extract-plugin"); - // Create a list of loaders that also contains the extraction loader - styleRule.use("style-loader").loader(MiniCssExtractPlugin.loader); + // Add plugin only once per bundle + if (!bundle.extractCSSConfigured) { + chain + .plugin("extractCSS") + .use(MiniCssExtractPlugin, [getExtractConfig(bundle)]); - chain - .plugin("extractCSS") - .use(MiniCssExtractPlugin, [getExtractConfig(bundle)]); + bundle.extractCSSConfigured = true; + } + + return MiniCssExtractPlugin.loader; } function createRule(crafty, bundle, chain, styleRule, options) { @@ -96,14 +94,15 @@ function createRule(crafty, bundle, chain, styleRule, options) { // "style" loader turns CSS into JS modules that inject