Skip to content

Commit 49e9f94

Browse files
committed
feat: allow default exports on .server. files
1 parent bc814ae commit 49e9f94

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

playground/lib/todo.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export async function getTodos () {
55
return todos
66
}
77

8+
export default getTodos
9+
810
export function getTodo (id: number) {
911
return prisma.todo.findFirstOrThrow({
1012
where: {

playground/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { useAsyncData } from '#app'
3-
import { deleteTodo, toggleTodo, getTodos } from '~~/lib/todo.server'
3+
import getTodos, { deleteTodo, toggleTodo } from '~~/lib/todo.server'
44
55
const { data: todos, refresh } = await useAsyncData(() => getTodos())
66

src/runtime/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function transformExports (src: string, moduleId: string) {
3737

3838
const exportList = exports.map((e) => {
3939
if (e.n === 'default') {
40-
throw new Error('Default exports are not allowed!')
40+
return `export default (...args) => useRemoteFunction('${moduleId}.${e.n}', args)`
4141
}
4242

4343
return `export const ${e.n} = (...args) => useRemoteFunction('${moduleId}.${e.n}', args)`

0 commit comments

Comments
 (0)