From d0c8fcbaa51b1ef5a4d6d970efb6f5ddb5c7381c Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Thu, 13 Dec 2018 18:37:47 +0000 Subject: [PATCH] fix: duplicate style in extractCSS (#4546) [skip ci] --- packages/webpack/src/utils/style-loader.js | 37 +++++++++------------- test/unit/extract-css.test.js | 4 ++- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/packages/webpack/src/utils/style-loader.js b/packages/webpack/src/utils/style-loader.js index 76fd68359c..c79010993b 100644 --- a/packages/webpack/src/utils/style-loader.js +++ b/packages/webpack/src/utils/style-loader.js @@ -1,5 +1,5 @@ import path from 'path' -import ExtractCssChunks from 'extract-css-chunks-webpack-plugin' +import ExtractCssChunksPlugin from 'extract-css-chunks-webpack-plugin' import { wrapArray } from '@nuxt/common' @@ -27,6 +27,10 @@ export default class StyleLoader { } } + get exportOnlyLocals() { + return Boolean(this.isServer && this.extractCSS) + } + normalize(loaders) { loaders = wrapArray(loaders) return loaders.map(loader => (typeof loader === 'string' ? { loader } : loader)) @@ -64,32 +68,25 @@ export default class StyleLoader { } css(options) { - if (this.isServer && this.extractCSS) { - options.exportOnlyLocals = true - } - return { - loader: 'css-loader', - options - } + options.exportOnlyLocals = this.exportOnlyLocals + return [ + ...options.exportOnlyLocals ? [] : [this.styleLoader()], + { loader: 'css-loader', options } + ] } cssModules(options) { - options.modules = true - return { - loader: 'css-loader', - options - } + return this.css(Object.assign(options, { modules: true })) } extract() { - if (this.extractCSS && !this.isServer) { - return ExtractCssChunks.loader + if (this.extractCSS) { + return ExtractCssChunksPlugin.loader } } - vueStyle() { - // https://github.com/vuejs/vue-style-loader - return { + styleLoader() { + return this.extract() || { loader: 'vue-style-loader', options: this.loaders.vueStyle } @@ -104,14 +101,11 @@ export default class StyleLoader { this.loaders.css.importLoaders = this.loaders.cssModules.importLoaders = customLoaders.length - const styleLoader = this.extract() || this.vueStyle() - return [ // This matches