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
+
1
6
export const clearModuleCache = moduleName => {
2
- const m = require . cache [ moduleName ]
7
+ const { cache } = getRequire ( ) ;
8
+ const m = cache [ moduleName ]
3
9
if ( m ) {
4
10
// remove self from own parents
5
11
if ( m . parent && m . parent . children ) {
@@ -13,7 +19,7 @@ export const clearModuleCache = moduleName => {
13
19
}
14
20
} )
15
21
}
16
- delete require . cache [ moduleName ]
22
+ delete cache [ moduleName ]
17
23
}
18
24
}
19
25
@@ -22,16 +28,7 @@ export const smartRequire = modulePath => {
22
28
clearModuleCache ( modulePath )
23
29
}
24
30
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 )
35
32
}
36
33
37
34
export const joinURLPath = ( publicPath , filename ) => {
0 commit comments