-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
nuxt.config.ts
219 lines (215 loc) · 5.65 KB
/
nuxt.config.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import { addBuildPlugin, addComponent } from 'nuxt/kit'
import type { NuxtPage } from 'nuxt/schema'
import { createUnplugin } from 'unplugin'
import { withoutLeadingSlash } from 'ufo'
// (defined in nuxt/src/core/nitro.ts)
declare module 'nitropack' {
interface NitroRouteConfig {
ssr?: boolean
}
}
export default defineNuxtConfig({
typescript: {
strict: true,
tsConfig: {
compilerOptions: {
moduleResolution: process.env.MODULE_RESOLUTION
}
}
},
app: {
pageTransition: true,
layoutTransition: true,
head: {
charset: 'utf-8',
link: [undefined],
meta: [
{ name: 'viewport', content: 'width=1024, initial-scale=1' },
{ charset: 'utf-8' },
{ name: 'description', content: 'Nuxt Fixture' }
]
}
},
buildDir: process.env.NITRO_BUILD_DIR,
builder: process.env.TEST_BUILDER as 'webpack' | 'vite' ?? 'vite',
build: {
transpile: [
(ctx) => {
if (typeof ctx.isDev !== 'boolean') { throw new TypeError('context not passed') }
return false
}
]
},
theme: './extends/bar',
css: ['~/assets/global.css'],
extends: [
'./extends/node_modules/foo'
],
nitro: {
routeRules: {
'/route-rules/spa': { ssr: false },
'/no-scripts': { experimentalNoScripts: true }
},
output: { dir: process.env.NITRO_OUTPUT_DIR },
prerender: {
routes: [
'/random/a',
'/random/b',
'/random/c'
]
}
},
optimization: {
keyedComposables: [
{
name: 'useKeyedComposable',
argumentLength: 1
}
]
},
runtimeConfig: {
baseURL: '',
baseAPIToken: '',
privateConfig: 'secret_key',
public: {
ids: [1, 2, 3],
needsFallback: undefined,
testConfig: 123
}
},
modules: [
[
'~/modules/example',
{
typeTest (val) {
// @ts-expect-error module type defines val as boolean
const b: string = val
return !!b
}
}
],
function (_, nuxt) {
if (typeof nuxt.options.builder === 'string' && nuxt.options.builder.includes('webpack')) { return }
nuxt.options.css.push('virtual.css')
nuxt.options.build.transpile.push('virtual.css')
const plugin = createUnplugin(() => ({
name: 'virtual',
resolveId (id) {
if (id === 'virtual.css') { return 'virtual.css' }
},
load (id) {
if (id === 'virtual.css') { return ':root { --virtual: red }' }
}
}))
addBuildPlugin(plugin)
},
function (_options, nuxt) {
const routesToDuplicate = ['/async-parent', '/fixed-keyed-child-parent', '/keyed-child-parent', '/with-layout', '/with-layout2']
const stripLayout = (page: NuxtPage): NuxtPage => ({
...page,
children: page.children?.map(child => stripLayout(child)),
name: 'internal-' + page.name,
path: withoutLeadingSlash(page.path),
meta: {
...page.meta || {},
layout: undefined,
_layout: page.meta?.layout
}
})
nuxt.hook('pages:extend', (pages) => {
const newPages = []
for (const page of pages) {
if (routesToDuplicate.includes(page.path)) {
newPages.push(stripLayout(page))
}
}
const internalParent = pages.find(page => page.path === '/internal-layout')
internalParent!.children = newPages
})
},
function (_, nuxt) {
nuxt.options.optimization.treeShake.composables.server[nuxt.options.rootDir] = ['useClientOnlyComposable', 'setTitleToPink']
nuxt.options.optimization.treeShake.composables.client[nuxt.options.rootDir] = ['useServerOnlyComposable']
},
// To test falsy module values
undefined
],
vite: {
logLevel: 'silent'
},
telemetry: false, // for testing telemetry types - it is auto-disabled in tests
hooks: {
'schema:extend' (schemas) {
schemas.push({
appConfig: {
someThing: {
value: {
$default: 'default',
$schema: {
tsType: 'string | false'
}
}
}
}
})
},
'prepare:types' ({ tsConfig }) {
tsConfig.include = tsConfig.include!.filter(i => i !== '../../../../**/*')
},
'modules:done' () {
addComponent({
name: 'CustomComponent',
export: 'namedExport',
filePath: '~/other-components-folder/named-export'
})
},
'vite:extendConfig' (config) {
config.plugins!.push({
name: 'nuxt:server',
configureServer (server) {
server.middlewares.use((req, res, next) => {
if (req.url === '/vite-plugin-without-path') {
res.end('vite-plugin without path')
return
}
next()
})
server.middlewares.use((req, res, next) => {
if (req.url === '/__nuxt-test') {
res.end('vite-plugin with __nuxt prefix')
return
}
next()
})
}
})
}
},
vue: {
compilerOptions: {
isCustomElement: (tag) => {
return tag === 'custom-component'
}
}
},
experimental: {
watcher: 'granular',
typedPages: true,
polyfillVueUseHead: true,
renderJsonPayloads: process.env.TEST_PAYLOAD !== 'js',
respectNoSSRHeader: true,
clientFallback: true,
restoreState: true,
inlineSSRStyles: id => !!id && !id.includes('assets.vue'),
componentIslands: true,
reactivityTransform: true,
treeshakeClientOnly: true,
payloadExtraction: true
},
appConfig: {
fromNuxtConfig: true,
nested: {
val: 1
}
}
})