Skip to content

Commit ef5688a

Browse files
refactor: remove reloadAll option
1 parent e175c3d commit ef5688a

File tree

10 files changed

+5
-54
lines changed

10 files changed

+5
-54
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,6 @@ The `mini-css-extract-plugin` supports hot reloading of actual css files in deve
404404
Some options are provided to enable HMR of both standard stylesheets and locally scoped CSS or CSS modules.
405405
Below is an example configuration of mini-css for HMR use with CSS modules.
406406

407-
While we attempt to hmr css-modules. It is not easy to perform when code-splitting with custom chunk names.
408-
`reloadAll` is an option that should only be enabled if HMR isn't working correctly.
409-
The core challenge with css-modules is that when code-split, the chunk ids can and do end up different compared to the filename.
410-
411407
You should not use `HotModuleReplacementPlugin` plugin if you are using a `webpack-dev-server`.
412408
`webpack-dev-server` enables / disables HMR using `hot` option.
413409

@@ -439,10 +435,7 @@ module.exports = {
439435
use: [
440436
{
441437
loader: MiniCssExtractPlugin.loader,
442-
options: {
443-
// if hmr does not work, this is a forceful method.
444-
reloadAll: true,
445-
},
438+
options: {},
446439
},
447440
'css-loader',
448441
],

src/hmr/hotModuleReplacement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ module.exports = function (moduleId, options) {
216216
return;
217217
}
218218

219-
if (reloaded && !options.reloadAll) {
219+
if (reloaded) {
220220
console.log('[HMR] css reload %s', src.join(' '));
221221
} else {
222222
console.log('[HMR] Reload all css');

src/loader-options.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
"hmr": {
1919
"type": "boolean"
2020
},
21-
"reloadAll": {
22-
"type": "boolean"
23-
},
2421
"modules": {
2522
"type": "object",
2623
"additionalProperties": false,

test/HMR.test.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,31 +126,6 @@ describe('HMR', () => {
126126
}, 100);
127127
});
128128

129-
it('should reloads with reloadAll option', (done) => {
130-
const update = hotModuleReplacement('./src/style.css', {
131-
reloadAll: true,
132-
});
133-
134-
update();
135-
136-
setTimeout(() => {
137-
expect(console.log.mock.calls[0][0]).toMatchSnapshot();
138-
139-
const links = Array.prototype.slice.call(
140-
document.querySelectorAll('link')
141-
);
142-
143-
expect(links[0].visited).toBe(true);
144-
expect(document.head.innerHTML).toMatchSnapshot();
145-
146-
links[1].dispatchEvent(getLoadEvent());
147-
148-
expect(links[1].isLoaded).toBe(true);
149-
150-
done();
151-
}, 100);
152-
});
153-
154129
it('should reloads with non http/https link href', (done) => {
155130
document.head.innerHTML =
156131
'<link rel="stylesheet" href="/dist/main.css" /><link rel="shortcut icon" href="data:;base64,=" />';

test/__snapshots__/HMR.test.js.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ exports[`HMR should reloads with non http/https link href 1`] = `"[HMR] css relo
2424
2525
exports[`HMR should reloads with non http/https link href 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"shortcut icon\\" href=\\"data:;base64,=\\">"`;
2626
27-
exports[`HMR should reloads with reloadAll option 1`] = `"[HMR] Reload all css"`;
28-
29-
exports[`HMR should reloads with reloadAll option 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;
30-
3127
exports[`HMR should works 1`] = `"[HMR] css reload %s"`;
3228
3329
exports[`HMR should works 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;

test/__snapshots__/validate-loader-options.test.js.snap

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,3 @@ options.publicPath should pass \\"instanceof\\" keyword validation
3636
options.publicPath should match some schema in anyOf
3737
"
3838
`;
39-
40-
exports[`validate options should throw an error on the "reloadAll" option with "1" value 1`] = `
41-
"Mini CSS Extract Plugin Loader Invalid Options
42-
43-
options.reloadAll should be boolean
44-
"
45-
`;

test/cases/hmr/expected/webpack-4/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ module.exports = function (moduleId, options) {
10921092
return;
10931093
}
10941094

1095-
if (reloaded && !options.reloadAll) {
1095+
if (reloaded) {
10961096
console.log('[HMR] css reload %s', src.join(' '));
10971097
} else {
10981098
console.log('[HMR] Reload all css');

test/cases/hmr/expected/webpack-5/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ module.exports = function (moduleId, options) {
234234
return;
235235
}
236236

237-
if (reloaded && !options.reloadAll) {
237+
if (reloaded) {
238238
console.log('[HMR] css reload %s', src.join(' '));
239239
} else {
240240
console.log('[HMR] Reload all css');

test/manual/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ if (module.hot) {
3434
replaceClass(localClass, classes[localClass]);
3535
});
3636
oldClasses = classes;
37+
// eslint-disable-next-line no-alert
3738
alert('HMR updated CSS module');
3839
});
3940
}

test/validate-loader-options.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ describe('validate options', () => {
1414
success: [true, false],
1515
failure: [1],
1616
},
17-
reloadAll: {
18-
success: [true, false],
19-
failure: [1],
20-
},
2117
modules: {
2218
success: [{ namedExport: true }, { namedExport: false }],
2319
failure: ['true', { namedExport: 'false' }],

0 commit comments

Comments
 (0)