mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-02-01 04:37:55 +01:00
fix: client auto-imports
This commit is contained in:
2
.nuxtrc
Normal file
2
.nuxtrc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
imports.autoImport=false
|
||||||
|
typescript.includeWorkspace=true
|
||||||
@@ -21,10 +21,11 @@
|
|||||||
"*.d.ts"
|
"*.d.ts"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublishOnly": "pnpm build",
|
|
||||||
"build": "nuxt-module-build",
|
"build": "nuxt-module-build",
|
||||||
"play": "pnpm build && nuxi dev playground",
|
"dev": "nuxi dev playground",
|
||||||
"build:playground": "nuxi build playground",
|
"dev:build": "nuxi build playground",
|
||||||
|
"dev:preview": "nuxi preview playground",
|
||||||
|
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"lint:fix": "eslint . --fix",
|
"lint:fix": "eslint . --fix",
|
||||||
"release": "bumpp --commit --push --tag && npm publish",
|
"release": "bumpp --commit --push --tag && npm publish",
|
||||||
@@ -52,7 +53,6 @@
|
|||||||
"bumpp": "^8.2.1",
|
"bumpp": "^8.2.1",
|
||||||
"eslint": "^8.25.0",
|
"eslint": "^8.25.0",
|
||||||
"nuxt": "3.0.0",
|
"nuxt": "3.0.0",
|
||||||
"trpc-nuxt": "workspace:*",
|
|
||||||
"zod": "^3.20.2"
|
"zod": "^3.20.2"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
const counter = useCookie('counter')
|
|
||||||
counter.value = counter.value || Math.round(Math.random() * 1000)
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<h1> Counter: {{ counter || '-' }}</h1>
|
|
||||||
<button @click="counter = null">
|
|
||||||
reset
|
|
||||||
</button>
|
|
||||||
<button @click="counter--">
|
|
||||||
-
|
|
||||||
</button>
|
|
||||||
<button @click="counter++">
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { useClient, useClientHeaders, useAsyncQuery } from '#imports'
|
||||||
const client = useClient()
|
const client = useClient()
|
||||||
const headers = useClientHeaders()
|
const headers = useClientHeaders()
|
||||||
const { data: todos, pending, error, refresh } = await useAsyncQuery(['getTodos'])
|
const { data: todos, pending, error, refresh } = await useAsyncQuery(['getTodos'])
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { useRoute, useAsyncQuery } from '#imports'
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(route.params.id)])
|
const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(route.params.id)])
|
||||||
</script>
|
</script>
|
||||||
@@ -11,8 +12,8 @@ const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(ro
|
|||||||
{{ error.data.code }}
|
{{ error.data.code }}
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
ID: {{ todo.id }} <br>
|
ID: {{ todo?.id }} <br>
|
||||||
Title: {{ todo.title }} <br>
|
Title: {{ todo?.title }} <br>
|
||||||
Completed: {{ todo.completed }}
|
Completed: {{ todo?.completed }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -18,7 +18,6 @@ importers:
|
|||||||
nuxt: 3.0.0
|
nuxt: 3.0.0
|
||||||
ohash: ^1.0.0
|
ohash: ^1.0.0
|
||||||
pathe: ^1.0.0
|
pathe: ^1.0.0
|
||||||
trpc-nuxt: workspace:*
|
|
||||||
ufo: ^1.0.1
|
ufo: ^1.0.1
|
||||||
zod: ^3.20.2
|
zod: ^3.20.2
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -38,7 +37,6 @@ importers:
|
|||||||
bumpp: 8.2.1
|
bumpp: 8.2.1
|
||||||
eslint: 8.26.0
|
eslint: 8.26.0
|
||||||
nuxt: 3.0.0_eslint@8.26.0
|
nuxt: 3.0.0_eslint@8.26.0
|
||||||
trpc-nuxt: 'link:'
|
|
||||||
zod: 3.20.2
|
zod: 3.20.2
|
||||||
|
|
||||||
playground:
|
playground:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
const logger = useLogger(metaName)
|
const logger = useLogger(metaName)
|
||||||
|
|
||||||
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
|
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
|
||||||
nuxt.options.build.transpile.push(runtimeDir, '#build/trpc-handler')
|
nuxt.options.build.transpile.push(runtimeDir)
|
||||||
|
|
||||||
const handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts')
|
const handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts')
|
||||||
const trpcOptionsPath = join(nuxt.options.srcDir, 'server/trpc')
|
const trpcOptionsPath = join(nuxt.options.srcDir, 'server/trpc')
|
||||||
@@ -49,7 +49,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
write: true,
|
write: true,
|
||||||
getContents() {
|
getContents() {
|
||||||
return dedent`
|
return dedent`
|
||||||
import { createTRPCHandler } from 'trpc-nuxt/api'
|
import { createTRPCHandler } from ${JSON.stringify(join(runtimeDir, 'api'))}
|
||||||
import * as functions from '${trpcOptionsPath}'
|
import * as functions from '${trpcOptionsPath}'
|
||||||
|
|
||||||
export default createTRPCHandler({
|
export default createTRPCHandler({
|
||||||
|
|||||||
Reference in New Issue
Block a user