-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathnuxt.config.ts
More file actions
64 lines (61 loc) · 2.26 KB
/
Copy pathnuxt.config.ts
File metadata and controls
64 lines (61 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// For pnpm typecheck:docs to generate correct types
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import { addPluginTemplate, addRouteMiddleware, addVitePlugin } from 'nuxt/kit'
export default defineNuxtConfig({
modules: [
function () {
if (!process.env.DOCS_TYPECHECK) { return }
addPluginTemplate({
filename: 'plugins/my-plugin.mjs',
getContents: () => 'export default defineNuxtPlugin({ name: \'my-plugin\' })',
})
addRouteMiddleware({
name: 'auth',
path: '#build/auth.js',
})
},
function (_options, nuxt) {
// this preserves onPrehydrate so we can make assertions on the client
nuxt.options.optimization.treeShake.composables.client ||= {}
nuxt.options.optimization.treeShake.composables.client['#app'] = nuxt.options.optimization.treeShake.composables.client['#app']?.filter(c => c !== 'onPrehydrate') || []
addVitePlugin(() => ({
name: 'preserve-ssr-composables',
enforce: 'pre',
transform (code, id) {
let replaced = false
// Strip the early client return so `onPrehydrate` runs under test.
// Scoped to the `onPrehydrate` function body so the same guard is
// left intact in sibling functions in `ssr.ts`.
const onPrehydrateStart = code.search(/(?:export\s+)?function onPrehydrate\s*\(/)
if (onPrehydrateStart !== -1) {
const head = code.slice(0, onPrehydrateStart)
const tail = code.slice(onPrehydrateStart).replace(/if \(import\.meta\.client\)\s*(?:\{\s*return\s*\}|return;?)/, '')
code = head + tail
replaced = true
}
if (id.includes('nuxt-time.vue')) {
replaced = true
code = code.replace('if (import.meta.server) {', 'if (useAttrs().ssr) {')
}
if (replaced) {
return code
}
},
}))
},
],
pages: process.env.DOCS_TYPECHECK === 'true',
dir: {
app: fileURLToPath(new URL('./test/runtime/app', import.meta.url)),
},
vite: {
define: {
'import.meta.dev': 'globalThis.__TEST_DEV__',
},
},
typescript: {
shim: process.env.DOCS_TYPECHECK === 'true',
hoist: ['@vitejs/plugin-vue', 'vue-router'],
},
})