Skip to content

Commit dbb708c

Browse files
fix: do not crash on using [fullhash] (#695)
1 parent d18cbfc commit dbb708c

File tree

22 files changed

+19528
-578
lines changed

22 files changed

+19528
-578
lines changed

package-lock.json

+19,065-535
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
"webpack-sources": "^1.1.0"
4949
},
5050
"devDependencies": {
51-
"@babel/cli": "^7.12.10",
52-
"@babel/core": "^7.12.10",
53-
"@babel/preset-env": "^7.12.11",
51+
"@babel/cli": "^7.12.13",
52+
"@babel/core": "^7.12.13",
53+
"@babel/preset-env": "^7.12.13",
5454
"@commitlint/cli": "^11.0.0",
5555
"@commitlint/config-conventional": "^11.0.0",
5656
"@webpack-contrib/defaults": "^6.3.0",
@@ -63,20 +63,20 @@
6363
"del": "^6.0.0",
6464
"del-cli": "^3.0.1",
6565
"es-check": "^5.2.0",
66-
"eslint": "^7.18.0",
66+
"eslint": "^7.19.0",
6767
"eslint-config-prettier": "^7.2.0",
6868
"eslint-plugin-import": "^2.22.1",
6969
"file-loader": "^6.2.0",
7070
"husky": "^4.3.8",
7171
"jest": "^26.6.3",
7272
"jsdom": "^16.4.0",
73-
"lint-staged": "^10.5.3",
73+
"lint-staged": "^10.5.4",
7474
"memfs": "^3.0.2",
7575
"npm-run-all": "^4.1.5",
7676
"prettier": "^2.2.1",
7777
"standard-version": "^9.1.0",
78-
"webpack": "^5.18.0",
79-
"webpack-cli": "^4.4.0",
78+
"webpack": "^5.21.1",
79+
"webpack-cli": "^4.5.0",
8080
"webpack-dev-server": "^3.7.2"
8181
},
8282
"keywords": [

src/index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,12 @@ class MiniCssExtractPlugin {
480480

481481
enabledChunks.add(chunk);
482482

483-
// eslint-disable-next-line global-require
484-
const CssLoadingRuntimeModule = require('./CssLoadingRuntimeModule');
483+
if (
484+
typeof this.options.chunkFilename === 'string' &&
485+
/\[(full)?hash(:\d+)?\]/.test(this.options.chunkFilename)
486+
) {
487+
set.add(webpack.RuntimeGlobals.getFullHash);
488+
}
485489

486490
set.add(webpack.RuntimeGlobals.publicPath);
487491

@@ -503,6 +507,10 @@ class MiniCssExtractPlugin {
503507
true
504508
)
505509
);
510+
511+
// eslint-disable-next-line global-require
512+
const CssLoadingRuntimeModule = require('./CssLoadingRuntimeModule');
513+
506514
compilation.addRuntimeModule(
507515
chunk,
508516
new CssLoadingRuntimeModule(set, this.runtimeOptions)

test/TestCases.test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,16 @@ describe('TestCases', () => {
179179
);
180180
} else {
181181
const matchAll = res.match(
182-
/__webpack_require__\.h = \(\) => "([\d\w].*)"/i
182+
/__webpack_require__\.h = \(\) => \(("[\d\w].*")\)/i
183183
);
184184

185185
const replacer = new Array(matchAll[1].length);
186186

187187
res = res.replace(
188-
/__webpack_require__\.h = \(\) => "([\d\w].*)"/i,
189-
`__webpack_require__.h = () => "${replacer.fill('x').join('')}"`
188+
/__webpack_require__\.h = \(\) => \(("[\d\w].*")\)/i,
189+
`__webpack_require__.h = () => ("${replacer
190+
.fill('x')
191+
.join('')}")`
190192
);
191193
}
192194

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.async {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.async {
2+
color: red;
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(self["webpackChunk"] = self["webpackChunk"] || []).push([[0],{
2+
3+
/***/ 2:
4+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
5+
6+
"use strict";
7+
__webpack_require__.r(__webpack_exports__);
8+
// extracted by mini-css-extract-plugin
9+
10+
11+
/***/ })
12+
13+
}]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: red;
3+
}
4+

0 commit comments

Comments
 (0)