From 5b8ab7ed744be8f105dac29e66c81186962daf8b Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Wed, 27 Jan 2021 18:05:44 +0300 Subject: [PATCH] fix: bloated runtime --- src/index.js | 11 ++++++++--- test/cases/runtime/expected/webpack-5/runtime~main.js | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index b9a88d0b..451415b3 100644 --- a/src/index.js +++ b/src/index.js @@ -477,10 +477,15 @@ class MiniCssExtractPlugin { MODULE_TYPE, 'mini-css', `${webpack.RuntimeGlobals.require}.miniCssF`, - (referencedChunk) => - referencedChunk.canBeInitial() + (referencedChunk) => { + if (!referencedChunk.contentHash[MODULE_TYPE]) { + return ''; + } + + return referencedChunk.canBeInitial() ? this.options.filename - : this.options.chunkFilename, + : this.options.chunkFilename; + }, true ) ); diff --git a/test/cases/runtime/expected/webpack-5/runtime~main.js b/test/cases/runtime/expected/webpack-5/runtime~main.js index 13ea0c61..181c1360 100644 --- a/test/cases/runtime/expected/webpack-5/runtime~main.js +++ b/test/cases/runtime/expected/webpack-5/runtime~main.js @@ -101,7 +101,7 @@ /******/ // This function allow to reference all chunks /******/ __webpack_require__.miniCssF = (chunkId) => { /******/ // return url for filenames based on template -/******/ return "" + ({"0":"main","1":"runtime~main"}[chunkId] || chunkId) + "." + {"0":"a7263f8f763dcf4051bc"}[chunkId] + ".css"; +/******/ return "" + "main" + "." + "a7263f8f763dcf4051bc" + ".css"; /******/ }; /******/ })(); /******/