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(ssr): resolve dynamic import vars modules #3177

Merged
merged 4 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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