fix: css extraction with MiniCssExtractPlugin

This commit is contained in:
Pooya Parsa 2018-03-24 01:07:59 +04:30
parent 17dbd2e947
commit 62cd611c19
2 changed files with 6 additions and 3 deletions

View File

@ -227,7 +227,10 @@ export default class WebpackBaseConfig {
} }
// CSS extraction // 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({ plugins.push(new MiniCssExtractPlugin(Object.assign({
filename: this.getFileName('css') filename: this.getFileName('css')
}, this.options.build.extractCSS))) }, this.options.build.extractCSS)))

View File

@ -70,7 +70,7 @@ export default class StyleLoader {
} }
return { return {
loader: 'css-loader', loader: (this.isServer && this.extractCSS) ? 'css-loader/locals' : 'css-loader',
options: { options: {
sourceMap: this.sourceMap, sourceMap: this.sourceMap,
minimize: !this.dev, minimize: !this.dev,
@ -81,7 +81,7 @@ export default class StyleLoader {
} }
extract() { extract() {
if (this.extractCSS) { if (this.extractCSS && !this.isServer) {
return MiniCssExtractPlugin.loader return MiniCssExtractPlugin.loader
} }
} }