Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Clear correct cache when compiling with Webpack #838

Merged
merged 2 commits into from
Sep 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/server/src/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Use __non_webpack_require__ to prevent Webpack from compiling it
// when the server-side code is compiled with Webpack
// eslint-disable-next-line camelcase, no-undef, global-require, import/no-dynamic-require, no-eval
const getRequire = () => typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : eval('require');

export const clearModuleCache = moduleName => {
const m = require.cache[moduleName]
const { cache } = getRequire();
const m = cache[moduleName]
if (m) {
// remove self from own parents
if (m.parent && m.parent.children) {
Expand All @@ -13,7 +19,7 @@ export const clearModuleCache = moduleName => {
}
})
}
delete require.cache[moduleName]
delete cache[moduleName]
}
}

Expand All @@ -22,16 +28,7 @@ export const smartRequire = modulePath => {
clearModuleCache(modulePath)
}

// Use __non_webpack_require__ to prevent Webpack from compiling it
// when the server-side code is compiled with Webpack
// eslint-disable-next-line camelcase
if (typeof __non_webpack_require__ !== 'undefined') {
// eslint-disable-next-line no-undef
return __non_webpack_require__(modulePath)
}

// eslint-disable-next-line global-require, import/no-dynamic-require, no-eval
return eval('require')(modulePath)
return getRequire()(modulePath)
}

export const joinURLPath = (publicPath, filename) => {
Expand Down