Skip to content

Commit

Permalink
fix: bloated runtime (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Jan 27, 2021
1 parent 05e2951 commit 70ce174
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,15 @@ class MiniCssExtractPlugin {
MODULE_TYPE,
'mini-css',
`${webpack.RuntimeGlobals.require}.miniCssF`,
(referencedChunk) =>
referencedChunk.canBeInitial()
(referencedChunk) => {
if (!referencedChunk.contentHash[MODULE_TYPE]) {
return false;
}

return referencedChunk.canBeInitial()
? this.options.filename
: this.options.chunkFilename,
: this.options.chunkFilename;
},
true
)
);
Expand Down
2 changes: 1 addition & 1 deletion test/cases/hmr/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ module.exports = function (urlString) {
/******/ // This function allow to reference all chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + "main" + ".css";
/******/ return undefined;
/******/ };
/******/ })();
/******/
Expand Down
1 change: 1 addition & 0 deletions test/cases/hmr/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Self from '../../../src';

module.exports = {
entry: './index.css',
mode: 'development',
module: {
rules: [
{
Expand Down
4 changes: 1 addition & 3 deletions test/cases/insert-function/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames not based on template
/******/ if (chunkId === 1) return "1.css";
/******/ // return url for filenames based on template
/******/ return "" + "main" + ".css";
/******/ return "" + chunkId + ".css";
/******/ };
/******/ })();
/******/
Expand Down
4 changes: 1 addition & 3 deletions test/cases/insert-string/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames not based on template
/******/ if (chunkId === 1) return "1.css";
/******/ // return url for filenames based on template
/******/ return "" + "main" + ".css";
/******/ return "" + chunkId + ".css";
/******/ };
/******/ })();
/******/
Expand Down
4 changes: 1 addition & 3 deletions test/cases/insert-undefined/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@
/******/ (() => {
/******/ // This function allow to reference all chunks
/******/ __webpack_require__.miniCssF = (chunkId) => {
/******/ // return url for filenames not based on template
/******/ if (chunkId === 1) return "1.css";
/******/ // return url for filenames based on template
/******/ return "" + "main" + ".css";
/******/ return "" + chunkId + ".css";
/******/ };
/******/ })();
/******/
Expand Down
2 changes: 1 addition & 1 deletion test/cases/runtime/expected/webpack-5/runtime~main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
/******/ };
/******/ })();
/******/
Expand Down

0 comments on commit 70ce174

Please sign in to comment.