Skip to content

Commit 3b9cb20

Browse files
MordredtheKashey
andauthored
fix: Clear correct cache when compiling with Webpack (#838)
* fix: Clear correct cache when compiling with Webpack * Update packages/server/src/util.js Co-authored-by: Anton Korzunov <[email protected]>
1 parent 1376eec commit 3b9cb20

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

packages/server/src/util.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
// Use __non_webpack_require__ to prevent Webpack from compiling it
2+
// when the server-side code is compiled with Webpack
3+
// eslint-disable-next-line camelcase, no-undef, global-require, import/no-dynamic-require, no-eval
4+
const getRequire = () => typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : eval('require');
5+
16
export const clearModuleCache = moduleName => {
2-
const m = require.cache[moduleName]
7+
const { cache } = getRequire();
8+
const m = cache[moduleName]
39
if (m) {
410
// remove self from own parents
511
if (m.parent && m.parent.children) {
@@ -13,7 +19,7 @@ export const clearModuleCache = moduleName => {
1319
}
1420
})
1521
}
16-
delete require.cache[moduleName]
22+
delete cache[moduleName]
1723
}
1824
}
1925

@@ -22,16 +28,7 @@ export const smartRequire = modulePath => {
2228
clearModuleCache(modulePath)
2329
}
2430

25-
// Use __non_webpack_require__ to prevent Webpack from compiling it
26-
// when the server-side code is compiled with Webpack
27-
// eslint-disable-next-line camelcase
28-
if (typeof __non_webpack_require__ !== 'undefined') {
29-
// eslint-disable-next-line no-undef
30-
return __non_webpack_require__(modulePath)
31-
}
32-
33-
// eslint-disable-next-line global-require, import/no-dynamic-require, no-eval
34-
return eval('require')(modulePath)
31+
return getRequire()(modulePath)
3532
}
3633

3734
export const joinURLPath = (publicPath, filename) => {

0 commit comments

Comments
 (0)