Skip to content

Commit

Permalink
fix(ssr): resolve dynamic import vars modules (#3177)
Browse files Browse the repository at this point in the history
Co-authored-by: Shinigami <chrissi92@hotmail.de>
  • Loading branch information
underfin and Shinigami92 committed May 5, 2021
1 parent 1178d08 commit b1e7395
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/playground/ssr-vue/src/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
<script setup>
import foo from '@foo'
import { reactive, defineAsyncComponent } from 'vue'
import ImportType from '../components/ImportType.vue'
const ImportType = load('ImportType')
const Foo = defineAsyncComponent(() =>
import('../components/Foo').then((mod) => mod.Foo)
)
function load(file) {
return defineAsyncComponent(() => import(`../components/${file}.vue`))
}
const state = reactive({ count: 0 })
</script>

Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ async function instantiateModule(
if (isExternal(dep)) {
return Promise.resolve(nodeRequire(dep, mod.file, server.config.root))
} else {
// #3087 dynamic import vars is ignored at rewrite import path,
// so here need process relative path
if (dep.startsWith('.')) {
dep = path.posix.resolve(path.dirname(url), dep)
}
return ssrLoadModule(dep, server, context, urlStack.concat(url))
}
}
Expand Down

0 comments on commit b1e7395

Please sign in to comment.