From a51fbae6ce9af217ce899f76de4d569c6ff08b4c Mon Sep 17 00:00:00 2001 From: LaySent Date: Sat, 23 Nov 2019 14:39:45 +0800 Subject: [PATCH] fix: only output when any chunk is fulfilled --- src/index.js | 7 ++-- .../ignoreOrderFalseWithoutGoodChunks/e1.css | 3 ++ .../ignoreOrderFalseWithoutGoodChunks/e2.css | 3 ++ .../ignoreOrderFalseWithoutGoodChunks/e3.css | 3 ++ .../ignoreOrderFalseWithoutGoodChunks/e4.css | 3 ++ .../expected/styles.css | 16 +++++++++ .../index.js | 1 + .../index2.js | 2 ++ .../index3.js | 3 ++ .../index4.js | 3 ++ .../warnings.js | 27 ++++++++++++++ .../webpack.config.js | 35 +++++++++++++++++++ 12 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/e1.css create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/e2.css create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/e3.css create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/e4.css create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/expected/styles.css create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/index.js create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/index2.js create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/index3.js create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/index4.js create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/warnings.js create mode 100644 test/cases/ignoreOrderFalseWithoutGoodChunks/webpack.config.js diff --git a/src/index.js b/src/index.js index 4b34a8aa..a21eab13 100644 --- a/src/index.js +++ b/src/index.js @@ -514,8 +514,11 @@ class MiniCssExtractPlugin { return [ ` * ${m.readableIdentifier(requestShortener)}`, ` - couldn't fulfill desired order of chunk group(s) ${failedChunkGroups}`, - ` - while fulfilling desired order of chunk group(s) ${goodChunkGroups}`, - ].join('\n'); + goodChunkGroups && + ` - while fulfilling desired order of chunk group(s) ${goodChunkGroups}`, + ] + .filter(Boolean) + .join('\n'); }), ].join('\n') ) diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/e1.css b/test/cases/ignoreOrderFalseWithoutGoodChunks/e1.css new file mode 100644 index 00000000..b3a307e8 --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/e1.css @@ -0,0 +1,3 @@ +body { + content: 'e1'; +} diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/e2.css b/test/cases/ignoreOrderFalseWithoutGoodChunks/e2.css new file mode 100644 index 00000000..f651f0fc --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/e2.css @@ -0,0 +1,3 @@ +body { + content: 'e2'; +} diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/e3.css b/test/cases/ignoreOrderFalseWithoutGoodChunks/e3.css new file mode 100644 index 00000000..bd54bb75 --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/e3.css @@ -0,0 +1,3 @@ +body { + content: 'e3'; +} diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/e4.css b/test/cases/ignoreOrderFalseWithoutGoodChunks/e4.css new file mode 100644 index 00000000..1e6308ef --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/e4.css @@ -0,0 +1,3 @@ +body { + content: 'e4'; +} diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/expected/styles.css b/test/cases/ignoreOrderFalseWithoutGoodChunks/expected/styles.css new file mode 100644 index 00000000..b1cc4dc0 --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/expected/styles.css @@ -0,0 +1,16 @@ +body { + content: 'e1'; +} + +body { + content: 'e4'; +} + +body { + content: 'e2'; +} + +body { + content: 'e3'; +} + diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/index.js b/test/cases/ignoreOrderFalseWithoutGoodChunks/index.js new file mode 100644 index 00000000..d2b747d5 --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/index.js @@ -0,0 +1 @@ +import './e1.css'; diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/index2.js b/test/cases/ignoreOrderFalseWithoutGoodChunks/index2.js new file mode 100644 index 00000000..af315736 --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/index2.js @@ -0,0 +1,2 @@ +import './e2.css'; +import './e1.css'; diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/index3.js b/test/cases/ignoreOrderFalseWithoutGoodChunks/index3.js new file mode 100644 index 00000000..8264cc8a --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/index3.js @@ -0,0 +1,3 @@ +import './e3.css'; +import './e4.css'; +import './e2.css'; diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/index4.js b/test/cases/ignoreOrderFalseWithoutGoodChunks/index4.js new file mode 100644 index 00000000..27a505ed --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/index4.js @@ -0,0 +1,3 @@ +import './e4.css'; +import './e2.css'; +import './e3.css'; diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/warnings.js b/test/cases/ignoreOrderFalseWithoutGoodChunks/warnings.js new file mode 100644 index 00000000..0d2d5768 --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/warnings.js @@ -0,0 +1,27 @@ +const cssLoaderPath = require.resolve('css-loader').replace(/\\/g, '/'); + +module.exports = [ + '', + 'WARNING in chunk styles [mini-css-extract-plugin]', + 'Conflicting order. Following module has been added:', + ` * css ${cssLoaderPath}!./e1.css`, + 'despite it was not able to fulfill desired ordering with these modules:', + ` * css ${cssLoaderPath}!./e2.css`, + " - couldn't fulfill desired order of chunk group(s) entry2", + '', + 'WARNING in chunk styles [mini-css-extract-plugin]', + 'Conflicting order. Following module has been added:', + ` * css ${cssLoaderPath}!./e4.css`, + 'despite it was not able to fulfill desired ordering with these modules:', + ` * css ${cssLoaderPath}!./e3.css`, + " - couldn't fulfill desired order of chunk group(s) entry3", + ' - while fulfilling desired order of chunk group(s) entry4', + '', + 'WARNING in chunk styles [mini-css-extract-plugin]', + 'Conflicting order. Following module has been added:', + ` * css ${cssLoaderPath}!./e2.css`, + 'despite it was not able to fulfill desired ordering with these modules:', + ` * css ${cssLoaderPath}!./e3.css`, + " - couldn't fulfill desired order of chunk group(s) entry3", + ' - while fulfilling desired order of chunk group(s) entry4', +].join('\n'); diff --git a/test/cases/ignoreOrderFalseWithoutGoodChunks/webpack.config.js b/test/cases/ignoreOrderFalseWithoutGoodChunks/webpack.config.js new file mode 100644 index 00000000..18ff2341 --- /dev/null +++ b/test/cases/ignoreOrderFalseWithoutGoodChunks/webpack.config.js @@ -0,0 +1,35 @@ +import Self from '../../../src'; + +module.exports = { + entry: { + entry1: './index.js', + entry2: './index2.js', + entry3: './index3.js', + entry4: './index4.js', + }, + module: { + rules: [ + { + test: /\.css$/, + use: [Self.loader, 'css-loader'], + }, + ], + }, + optimization: { + splitChunks: { + cacheGroups: { + styles: { + name: 'styles', + chunks: 'all', + test: /\.css$/, + enforce: true, + }, + }, + }, + }, + plugins: [ + new Self({ + ignoreOrder: false, + }), + ], +};