Skip to content

Commit 57ad127

Browse files
authoredNov 4, 2021
fix: crash with [contenthash] (#869)
1 parent b4be280 commit 57ad127

File tree

20 files changed

+96
-40
lines changed

20 files changed

+96
-40
lines changed
 

‎src/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,7 @@ class MiniCssExtractPlugin {
821821
return referencedChunk.canBeInitial()
822822
? this.options.filename
823823
: this.options.chunkFilename;
824-
},
825-
true
824+
}
826825
)
827826
);
828827

‎test/TestCases.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe("TestCases", () => {
114114
Object.assign(
115115
config,
116116
{
117-
mode: "none",
117+
mode: config.mode || "none",
118118
context: directoryForCase,
119119
},
120120
config,

‎test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,16 @@ __webpack_require__.r(__webpack_exports__);
6464
/******/
6565
/******/ /* webpack/runtime/get mini-css chunk filename */
6666
/******/ (() => {
67-
/******/ // This function allow to reference all chunks
67+
/******/ // This function allow to reference async chunks
6868
/******/ __webpack_require__.miniCssF = (chunkId) => {
69-
/******/ // return url for filenames not based on template
70-
/******/ if (chunkId === 1) return "" + __webpack_require__.h() + ".css";
7169
/******/ // return url for filenames based on template
7270
/******/ return "" + chunkId + "." + __webpack_require__.h() + ".css";
7371
/******/ };
7472
/******/ })();
7573
/******/
7674
/******/ /* webpack/runtime/getFullHash */
7775
/******/ (() => {
78-
/******/ __webpack_require__.h = () => ("b39c6cd65ee4f78b425e")
76+
/******/ __webpack_require__.h = () => ("28af1b92f2511f8f1836")
7977
/******/ })();
8078
/******/
8179
/******/ /* webpack/runtime/global */

‎test/cases/chunkFilename-fullhash/expected/webpack-5/main.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,16 @@ __webpack_require__.r(__webpack_exports__);
6464
/******/
6565
/******/ /* webpack/runtime/get mini-css chunk filename */
6666
/******/ (() => {
67-
/******/ // This function allow to reference all chunks
67+
/******/ // This function allow to reference async chunks
6868
/******/ __webpack_require__.miniCssF = (chunkId) => {
69-
/******/ // return url for filenames not based on template
70-
/******/ if (chunkId === 1) return "" + __webpack_require__.h() + ".css";
7169
/******/ // return url for filenames based on template
7270
/******/ return "" + chunkId + "." + __webpack_require__.h() + ".css";
7371
/******/ };
7472
/******/ })();
7573
/******/
7674
/******/ /* webpack/runtime/getFullHash */
7775
/******/ (() => {
78-
/******/ __webpack_require__.h = () => ("4119f46f7fa72336b928")
76+
/******/ __webpack_require__.h = () => ("845a2495b51038b0d047")
7977
/******/ })();
8078
/******/
8179
/******/ /* webpack/runtime/global */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

‎test/cases/contenthash-1/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* eslint-disable */
2+
async () => await import("./lib.js");
3+
import "./style.css";

‎test/cases/contenthash-1/lib.js

Whitespace-only changes.

‎test/cases/contenthash-1/style.css

Whitespace-only changes.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Self from "../../../src";
2+
3+
module.exports = {
4+
entry: "./index.js",
5+
mode: "production",
6+
cache: {
7+
type: "filesystem",
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: /\.css$/,
13+
use: [Self.loader, "css-loader"],
14+
},
15+
],
16+
},
17+
output: {
18+
filename: "[name].[contenthash].js",
19+
},
20+
plugins: [
21+
new Self({
22+
filename: "[name].[contenthash].css",
23+
}),
24+
],
25+
};

‎test/cases/hmr/expected/main.css

+18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
/*!****************************************************************!*\
2+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./c.css ***!
3+
\****************************************************************/
14
@import url(https://some/other/external/css);
5+
/*!****************************************************************!*\
6+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./b.css ***!
7+
\****************************************************************/
28
@import url(https://some/external/css);
9+
/*!****************************************************************!*\
10+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./a.css ***!
11+
\****************************************************************/
312
body {
413
background: red;
514
}
615

16+
/*!********************************************************************!*\
17+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./c.css (1) ***!
18+
\********************************************************************/
719
.c {
820
background: red;
921
}
@@ -12,6 +24,9 @@ body {
1224
color: yellow;
1325
}
1426

27+
/*!********************************************************************!*\
28+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./b.css (1) ***!
29+
\********************************************************************/
1530
.b {
1631
background: red;
1732
}
@@ -20,5 +35,8 @@ body {
2035
color: yellow;
2136
}
2237

38+
/*!********************************************************************!*\
39+
!*** css ../../../node_modules/css-loader/dist/cjs.js!./index.css ***!
40+
\********************************************************************/
2341

2442

‎test/cases/hmr/expected/main.js

+37-24
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
/******/ (() => { // webpackBootstrap
2-
/******/ var __webpack_modules__ = ([
3-
/* 0 */
4-
/***/ ((module, __webpack_exports__, __webpack_require__) => {
5-
6-
"use strict";
7-
__webpack_require__.r(__webpack_exports__);
8-
// extracted by mini-css-extract-plugin
9-
10-
if(true) {
11-
//
12-
var cssReload = __webpack_require__(1)(module.id, {"locals":false});
13-
module.hot.dispose(cssReload);
14-
module.hot.accept(undefined, cssReload);
15-
}
16-
2+
/******/ var __webpack_modules__ = ({
173

18-
/***/ }),
19-
/* 1 */
4+
/***/ "../../../src/hmr/hotModuleReplacement.js":
5+
/*!************************************************!*\
6+
!*** ../../../src/hmr/hotModuleReplacement.js ***!
7+
\************************************************/
208
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
219

2210
/* eslint-env browser */
@@ -26,7 +14,7 @@ __webpack_require__.r(__webpack_exports__);
2614
func-names
2715
*/
2816

29-
const normalizeUrl = __webpack_require__(2);
17+
const normalizeUrl = __webpack_require__(/*! ./normalize-url */ "../../../src/hmr/normalize-url.js");
3018

3119
const srcByModuleId = Object.create(null);
3220

@@ -262,7 +250,11 @@ module.exports = function (moduleId, options) {
262250

263251

264252
/***/ }),
265-
/* 2 */
253+
254+
/***/ "../../../src/hmr/normalize-url.js":
255+
/*!*****************************************!*\
256+
!*** ../../../src/hmr/normalize-url.js ***!
257+
\*****************************************/
266258
/***/ ((module) => {
267259

268260
/* eslint-disable */
@@ -305,8 +297,29 @@ module.exports = function (urlString) {
305297
};
306298

307299

300+
/***/ }),
301+
302+
/***/ "./index.css":
303+
/*!*******************!*\
304+
!*** ./index.css ***!
305+
\*******************/
306+
/***/ ((module, __webpack_exports__, __webpack_require__) => {
307+
308+
"use strict";
309+
__webpack_require__.r(__webpack_exports__);
310+
// extracted by mini-css-extract-plugin
311+
312+
if(true) {
313+
//
314+
var cssReload = __webpack_require__(/*! ../../../src/hmr/hotModuleReplacement.js */ "../../../src/hmr/hotModuleReplacement.js")(module.id, {"locals":false});
315+
module.hot.dispose(cssReload);
316+
module.hot.accept(undefined, cssReload);
317+
}
318+
319+
308320
/***/ })
309-
/******/ ]);
321+
322+
/******/ });
310323
/************************************************************************/
311324
/******/ // The module cache
312325
/******/ var __webpack_module_cache__ = {};
@@ -362,10 +375,10 @@ module.exports = function (urlString) {
362375
/******/
363376
/******/ /* webpack/runtime/get mini-css chunk filename */
364377
/******/ (() => {
365-
/******/ // This function allow to reference all chunks
378+
/******/ // This function allow to reference async chunks
366379
/******/ __webpack_require__.miniCssF = (chunkId) => {
367380
/******/ // return url for filenames based on template
368-
/******/ return "" + "main" + ".css";
381+
/******/ return undefined;
369382
/******/ };
370383
/******/ })();
371384
/******/
@@ -947,7 +960,7 @@ module.exports = function (urlString) {
947960
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
948961
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
949962
/******/ var installedChunks = __webpack_require__.hmrS_jsonp = __webpack_require__.hmrS_jsonp || {
950-
/******/ 0: 0
963+
/******/ "main": 0
951964
/******/ };
952965
/******/
953966
/******/ // no chunk on demand loading
@@ -1457,7 +1470,7 @@ module.exports = function (urlString) {
14571470
/******/ // module cache are used so entry inlining is disabled
14581471
/******/ // startup
14591472
/******/ // Load entry module and return exports
1460-
/******/ var __webpack_exports__ = __webpack_require__(0);
1473+
/******/ var __webpack_exports__ = __webpack_require__("./index.css");
14611474
/******/
14621475
/******/ })()
14631476
;

‎test/cases/hmr/webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Self from "../../../src";
55
module.exports = {
66
entry: "./index.css",
77
mode: "development",
8+
devtool: false,
89
module: {
910
rules: [
1011
{

‎test/cases/insert-function/expected/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
/******/
5454
/******/ /* webpack/runtime/get mini-css chunk filename */
5555
/******/ (() => {
56-
/******/ // This function allow to reference all chunks
56+
/******/ // This function allow to reference async chunks
5757
/******/ __webpack_require__.miniCssF = (chunkId) => {
5858
/******/ // return url for filenames based on template
5959
/******/ return "" + chunkId + ".css";

‎test/cases/insert-string/expected/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
/******/
5454
/******/ /* webpack/runtime/get mini-css chunk filename */
5555
/******/ (() => {
56-
/******/ // This function allow to reference all chunks
56+
/******/ // This function allow to reference async chunks
5757
/******/ __webpack_require__.miniCssF = (chunkId) => {
5858
/******/ // return url for filenames based on template
5959
/******/ return "" + chunkId + ".css";

‎test/cases/insert-undefined/expected/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
/******/
5454
/******/ /* webpack/runtime/get mini-css chunk filename */
5555
/******/ (() => {
56-
/******/ // This function allow to reference all chunks
56+
/******/ // This function allow to reference async chunks
5757
/******/ __webpack_require__.miniCssF = (chunkId) => {
5858
/******/ // return url for filenames based on template
5959
/******/ return "" + chunkId + ".css";

‎test/cases/runtime/expected/runtime~main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@
128128
/******/
129129
/******/ /* webpack/runtime/get mini-css chunk filename */
130130
/******/ (() => {
131-
/******/ // This function allow to reference all chunks
131+
/******/ // This function allow to reference async chunks
132132
/******/ __webpack_require__.miniCssF = (chunkId) => {
133133
/******/ // return url for filenames based on template
134-
/******/ return "" + "main" + "." + "a45a4571ab5cece12cf0" + ".css";
134+
/******/ return undefined;
135135
/******/ };
136136
/******/ })();
137137
/******/

0 commit comments

Comments
 (0)
Please sign in to comment.