Skip to content

Commit

Permalink
refactor(ssr): use dynamicImport util from vitejs#5213
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Moore committed Oct 7, 2021
1 parent b5d24d3 commit 5bcdcba
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import path from 'path'
import { pathToFileURL } from 'url'
import { ViteDevServer } from '..'
import { cleanUrl, isBuiltin, isObject, resolveFrom, unwrapId } from '../utils'
import { dynamicImport, cleanUrl, isBuiltin, isObject, resolveFrom, unwrapId } from '../utils'
import { rebindErrorStacktrace, ssrRewriteStacktrace } from './ssrStacktrace'
import {
ssrExportAllKey,
Expand All @@ -13,11 +13,6 @@ import {
} from './ssrTransform'
import { transformRequest } from '../server/transformRequest'

// This is a workaround since typescript compiles dynamic imports to `require`.
// Thankfully, when `typescript@4.5.0` lands it won't and this can be removed!
// See #5197 for notes
const nativeImport = eval('u => import(u)')

interface SSRContext {
global: NodeJS.Global
}
Expand Down Expand Up @@ -190,7 +185,7 @@ async function nodeImport(
resolve(id, importer, config.root, !!config.resolve.preserveSymlinks)
).toString()
}
const mod = await nativeImport(url)
const mod = await dynamicImport(url)
return proxyESM(id, mod)
}

Expand Down

0 comments on commit 5bcdcba

Please sign in to comment.