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(config): only rewrite .js loader in loadConfigFromBundledFile #8556

Merged
merged 1 commit into from Jun 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/vite/src/node/config.ts
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