Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Commit e79875e

Browse files
feat: updating hmr css module system (faceyspacey#160)
* fix: removing modules option * fix: removing modules option and using css-loader passthru * fix: tests
1 parent 0c6ca8e commit e79875e

File tree

9 files changed

+519
-503
lines changed

9 files changed

+519
-503
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ module.exports = {
8181
loader:ExtractCssChunks.loader,
8282
options: {
8383
hot: true, // if you want HMR - we try to automatically inject hot reloading but if it's not working, add it to the config
84-
modules: true, // if you use cssModules, this can help.
8584
reloadAll: true, // when desperation kicks in - this is a brute force HMR flag
8685

8786
}
@@ -168,7 +167,6 @@ module.exports = {
168167
loader:ExtractCssChunks.loader,
169168
options: {
170169
hot: true,
171-
modules: true,
172170
reloadAll: true
173171
},
174172
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
},
6767
"dependencies": {
6868
"loader-utils": "^1.1.0",
69-
"normalize-url": "^3.0.0",
7069
"lodash": "^4.17.11",
70+
"normalize-url": "^2.0.1",
7171
"schema-utils": "^1.0.0",
7272
"webpack-sources": "^1.1.0"
7373
},
@@ -89,6 +89,7 @@
8989
"eslint": "^4.17.0",
9090
"eslint-plugin-import": "^2.8.0",
9191
"eslint-plugin-prettier": "^2.6.0",
92+
"execa": "^1.0.0",
9293
"file-loader": "^1.1.11",
9394
"husky": "^0.14.3",
9495
"jest": "^22.2.2",

src/hmr/hotModuleReplacement.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function reloadAll() {
144144

145145
module.exports = function(moduleId, options) {
146146
if (noDocument) {
147+
console.log('no window.document found, will not HMR CSS');
147148
return noop;
148149
}
149150

src/index.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -395,21 +395,6 @@ class ExtractCssChunksPlugin {
395395
});
396396
}
397397

398-
traverseDepthFirst(root, visit) {
399-
let nodesToVisit = [root];
400-
401-
while (nodesToVisit.length > 0) {
402-
const currentNode = nodesToVisit.shift();
403-
404-
if (currentNode !== null && typeof currentNode === 'object') {
405-
const children = Object.values(currentNode);
406-
nodesToVisit = [...children, ...nodesToVisit];
407-
}
408-
409-
visit(currentNode);
410-
}
411-
}
412-
413398
getCssChunkObject(mainChunk) {
414399
const obj = {};
415400
for (const chunk of mainChunk.getAllAsyncChunks()) {

src/loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const MODULE_TYPE = 'css/extract-css-chunks';
1313
const pluginName = 'extract-css-chunks-webpack-plugin';
1414

1515
function hotLoader(content, context) {
16-
const accept = context.modules
16+
const accept = context.locals
1717
? ''
1818
: 'module.hot.accept(undefined, cssReload);';
1919
const result = `${content}
@@ -155,7 +155,7 @@ export function pitch(request) {
155155
: '';
156156

157157
resultSource += query.hot
158-
? hotLoader(result, { context: this.context, query })
158+
? hotLoader(result, { context: this.context, query, locals })
159159
: result;
160160

161161
return callback(null, resultSource);

test/TestCases.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import { exec } from 'child_process';
43

54
import webpack from 'webpack';
5+
import execa from 'execa';
66

77
describe('TestCases', () => {
88
const casesDirectory = path.resolve(__dirname, 'cases');
@@ -89,13 +89,12 @@ describe('HMR', () => {
8989
});
9090

9191
it('is es5 only', () => {
92-
exec(
93-
'./node_modules/.bin/es-check es5 src/hmr/hotModuleReplacement.js',
94-
(error, stdout, stderr) => {
95-
expect(
96-
stderr.indexOf('there were no ES version matching errors!') > -1
97-
).toBe(true);
98-
}
92+
const { stderr } = execa.shellSync(
93+
'npx es-check es5 src/hmr/hotModuleReplacement.js'
9994
);
95+
96+
expect(
97+
stderr.indexOf('there were no ES version matching errors') > -1
98+
).toBe(true);
10099
});
101100
});

test/__snapshots__/TestCases.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ function reloadAll() {
147147
148148
module.exports = function(moduleId, options) {
149149
if (noDocument) {
150+
console.log('no window.document found, will not HMR CSS');
150151
return noop;
151152
}
152153

test/cases/hmr/expected/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
/***/ (function(module, exports, __webpack_require__) {
9090

9191
// extracted by extract-css-chunks-webpack-plugin
92+
if(false) { var cssReload; }
93+
9294

9395
/***/ })
9496
/******/ ]);

0 commit comments

Comments
 (0)