Skip to content

Commit

Permalink
fix(config): only rewrite .js loader in loadConfigFromBundledFile (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
CHOYSEN authored Jun 13, 2022
1 parent 9a1fd4c commit 2548dd3
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,9 @@ async function loadConfigFromBundledFile(
fileName: string,
bundledCode: string
): Promise<UserConfig> {
const extension = path.extname(fileName)
const realFileName = fs.realpathSync(fileName)
const defaultLoader = _require.extensions[extension]!
_require.extensions[extension] = (module: NodeModule, filename: string) => {
const defaultLoader = _require.extensions['.js']
_require.extensions['.js'] = (module: NodeModule, filename: string) => {
if (filename === realFileName) {
;(module as NodeModuleWithCompile)._compile(bundledCode, filename)
} else {
Expand All @@ -850,9 +849,8 @@ async function loadConfigFromBundledFile(
// clear cache in case of server restart
delete _require.cache[_require.resolve(fileName)]
const raw = _require(fileName)
const config = raw.__esModule ? raw.default : raw
_require.extensions[extension] = defaultLoader
return config
_require.extensions['.js'] = defaultLoader
return raw.__esModule ? raw.default : raw
}

export function isDepsOptimizerEnabled(config: ResolvedConfig): boolean {
Expand Down

0 comments on commit 2548dd3

Please sign in to comment.