Skip to content

Commit

Permalink
fix: use correct require extension to load config
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 14, 2022
1 parent 8e0308b commit 42a6d5b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,11 @@ async function loadConfigFromBundledFile(
fileName: string,
bundledCode: string
): Promise<UserConfig> {
const extension = path.extname(fileName)
const realFileName = fs.realpathSync(fileName)
const defaultLoader = _require.extensions['.js']
_require.extensions['.js'] = (module: NodeModule, filename: string) => {
const loaderExt = extension in _require.extensions ? extension : '.js'
const defaultLoader = _require.extensions[loaderExt]!
_require.extensions[loaderExt] = (module: NodeModule, filename: string) => {
if (filename === realFileName) {
;(module as NodeModuleWithCompile)._compile(bundledCode, filename)
} else {
Expand All @@ -990,7 +992,7 @@ async function loadConfigFromBundledFile(
// clear cache in case of server restart
delete _require.cache[_require.resolve(fileName)]
const raw = _require(fileName)
_require.extensions['.js'] = defaultLoader
_require.extensions[loaderExt] = defaultLoader
return raw.__esModule ? raw.default : raw
}

Expand Down

0 comments on commit 42a6d5b

Please sign in to comment.