Skip to content

Commit

Permalink
fix(ssr): respect ssr.external and ssr.noExternal
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Oct 4, 2021
1 parent eb7e113 commit d14ca7b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { transformRequest } from '../server/transformRequest'
import { injectSourcesContent } from '../server/sourcemap'
import { InternalResolveOptions, tryNodeResolve } from '../plugins/resolve'
import { hookNodeResolve } from '../plugins/ssrRequireHook'
import { shouldExternalizeForSSR } from './ssrExternal'

interface SSRContext {
global: NodeJS.Global
Expand Down Expand Up @@ -135,8 +136,13 @@ async function instantiateModule(
root
}

const isExternal = (dep: string) =>
server._ssrExternals
? shouldExternalizeForSSR(dep, server._ssrExternals)
: dep[0] !== '/'

const ssrImport = async (dep: string) => {
if (dep[0] !== '/') {
if (isExternal(dep)) {
return nodeRequire(dep, mod.file, resolveOptions)
}
if (!isCircular(dep) && !pendingImports.get(dep)?.some(isCircular)) {
Expand Down

0 comments on commit d14ca7b

Please sign in to comment.