diff --git a/lib/builder/webpack/base.mjs b/lib/builder/webpack/base.mjs index bcf451bebb..4737008fd4 100644 --- a/lib/builder/webpack/base.mjs +++ b/lib/builder/webpack/base.mjs @@ -227,7 +227,10 @@ export default class WebpackBaseConfig { } // CSS extraction - if (this.options.build.extractCSS) { + // MiniCssExtractPlugin does not currently supports SSR + // https://github.com/webpack-contrib/mini-css-extract-plugin/issues/48 + // So we use css-loader/locals as a fallback (utils/style-loader) + if (this.options.build.extractCSS && !this.isServer) { plugins.push(new MiniCssExtractPlugin(Object.assign({ filename: this.getFileName('css') }, this.options.build.extractCSS))) diff --git a/lib/builder/webpack/utils/style-loader.js b/lib/builder/webpack/utils/style-loader.js index 70b613d46f..05d32869b6 100644 --- a/lib/builder/webpack/utils/style-loader.js +++ b/lib/builder/webpack/utils/style-loader.js @@ -70,7 +70,7 @@ export default class StyleLoader { } return { - loader: 'css-loader', + loader: (this.isServer && this.extractCSS) ? 'css-loader/locals' : 'css-loader', options: { sourceMap: this.sourceMap, minimize: !this.dev, @@ -81,7 +81,7 @@ export default class StyleLoader { } extract() { - if (this.extractCSS) { + if (this.extractCSS && !this.isServer) { return MiniCssExtractPlugin.loader } }