2023-05-14 11:55:26 +00:00
|
|
|
import { addBuildPlugin, addComponent } from 'nuxt/kit'
|
2023-04-19 15:45:13 +00:00
|
|
|
import type { NuxtPage } from 'nuxt/schema'
|
2022-09-12 15:14:11 +00:00
|
|
|
import { createUnplugin } from 'unplugin'
|
2022-10-08 14:18:57 +00:00
|
|
|
import { withoutLeadingSlash } from 'ufo'
|
2021-04-23 19:52:32 +00:00
|
|
|
|
2022-10-27 10:36:37 +00:00
|
|
|
// (defined in nuxt/src/core/nitro.ts)
|
|
|
|
declare module 'nitropack' {
|
|
|
|
interface NitroRouteConfig {
|
|
|
|
ssr?: boolean
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 09:38:06 +00:00
|
|
|
export default defineNuxtConfig({
|
2022-08-07 09:53:53 +00:00
|
|
|
app: {
|
2022-10-24 15:23:49 +00:00
|
|
|
pageTransition: true,
|
|
|
|
layoutTransition: true,
|
2024-03-11 14:33:49 +00:00
|
|
|
teleportId: 'nuxt-teleport',
|
|
|
|
teleportTag: 'span',
|
2022-08-07 09:53:53 +00:00
|
|
|
head: {
|
|
|
|
charset: 'utf-8',
|
|
|
|
link: [undefined],
|
2023-03-08 15:32:24 +00:00
|
|
|
meta: [
|
|
|
|
{ name: 'viewport', content: 'width=1024, initial-scale=1' },
|
|
|
|
{ charset: 'utf-8' },
|
|
|
|
{ name: 'description', content: 'Nuxt Fixture' }
|
|
|
|
]
|
2023-11-14 16:56:31 +00:00
|
|
|
},
|
|
|
|
keepalive: {
|
|
|
|
include: ['keepalive-in-config', 'not-keepalive-in-nuxtpage']
|
2022-08-07 09:53:53 +00:00
|
|
|
}
|
|
|
|
},
|
2021-07-15 09:38:06 +00:00
|
|
|
buildDir: process.env.NITRO_BUILD_DIR,
|
2023-02-13 22:09:32 +00:00
|
|
|
builder: process.env.TEST_BUILDER as 'webpack' | 'vite' ?? 'vite',
|
2023-01-19 10:56:34 +00:00
|
|
|
build: {
|
|
|
|
transpile: [
|
|
|
|
(ctx) => {
|
|
|
|
if (typeof ctx.isDev !== 'boolean') { throw new TypeError('context not passed') }
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2022-09-03 13:03:30 +00:00
|
|
|
css: ['~/assets/global.css'],
|
2024-01-30 13:55:18 +00:00
|
|
|
// this produces an order of `~` > `~/extends/bar` > `~/extends/node_modules/foo`
|
|
|
|
theme: './extends/bar',
|
2022-03-22 18:12:54 +00:00
|
|
|
extends: [
|
2022-06-10 13:33:16 +00:00
|
|
|
'./extends/node_modules/foo'
|
2022-03-22 18:12:54 +00:00
|
|
|
],
|
2021-07-15 09:38:06 +00:00
|
|
|
nitro: {
|
2024-03-14 00:18:44 +00:00
|
|
|
publicAssets: [
|
|
|
|
{
|
|
|
|
dir: '../custom-public',
|
|
|
|
baseURL: '/custom'
|
|
|
|
}
|
|
|
|
],
|
2023-05-30 11:53:04 +00:00
|
|
|
esbuild: {
|
|
|
|
options: {
|
2023-10-10 11:14:55 +00:00
|
|
|
// in order to test bigint serialization
|
2023-05-30 11:53:04 +00:00
|
|
|
target: 'es2022'
|
|
|
|
}
|
|
|
|
},
|
2022-10-17 14:15:59 +00:00
|
|
|
routeRules: {
|
2023-04-11 14:17:44 +00:00
|
|
|
'/route-rules/spa': { ssr: false },
|
2024-03-16 18:53:01 +00:00
|
|
|
'/route-rules/middleware': { nuxtMiddleware: 'route-rules-middleware' },
|
2023-07-18 15:21:53 +00:00
|
|
|
'/hydration/spa-redirection/**': { ssr: false },
|
2023-04-11 14:17:44 +00:00
|
|
|
'/no-scripts': { experimentalNoScripts: true }
|
2022-10-11 16:03:52 +00:00
|
|
|
},
|
2022-09-10 13:57:16 +00:00
|
|
|
output: { dir: process.env.NITRO_OUTPUT_DIR },
|
|
|
|
prerender: {
|
|
|
|
routes: [
|
|
|
|
'/random/a',
|
|
|
|
'/random/b',
|
2023-09-19 21:31:18 +00:00
|
|
|
'/random/c',
|
|
|
|
'/prefetch/server-components'
|
2022-09-10 13:57:16 +00:00
|
|
|
]
|
|
|
|
}
|
2021-10-02 20:30:20 +00:00
|
|
|
},
|
2023-03-07 21:06:15 +00:00
|
|
|
optimization: {
|
|
|
|
keyedComposables: [
|
|
|
|
{
|
2023-06-05 19:15:12 +00:00
|
|
|
name: 'useCustomKeyedComposable',
|
2023-07-05 09:35:45 +00:00
|
|
|
source: '~/other-composables-folder/custom-keyed-composable',
|
2023-03-07 21:06:15 +00:00
|
|
|
argumentLength: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2022-11-16 02:26:35 +00:00
|
|
|
runtimeConfig: {
|
|
|
|
public: {
|
2023-01-28 15:18:04 +00:00
|
|
|
needsFallback: undefined,
|
2022-11-16 02:26:35 +00:00
|
|
|
testConfig: 123
|
|
|
|
}
|
2022-02-15 09:50:11 +00:00
|
|
|
},
|
2022-09-12 15:14:11 +00:00
|
|
|
modules: [
|
2023-12-12 17:55:21 +00:00
|
|
|
'~/modules/subpath',
|
2023-05-20 22:29:32 +00:00
|
|
|
'./modules/test',
|
2023-05-22 19:44:03 +00:00
|
|
|
'~/modules/example',
|
2022-09-12 15:14:11 +00:00
|
|
|
function (_, nuxt) {
|
2023-02-13 22:09:32 +00:00
|
|
|
if (typeof nuxt.options.builder === 'string' && nuxt.options.builder.includes('webpack')) { return }
|
2022-09-12 15:14:11 +00:00
|
|
|
|
|
|
|
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 }' }
|
|
|
|
}
|
|
|
|
}))
|
2023-05-14 11:55:26 +00:00
|
|
|
addBuildPlugin(plugin)
|
2022-10-08 14:18:57 +00:00
|
|
|
},
|
2024-02-07 10:00:19 +00:00
|
|
|
function (_options, nuxt) {
|
2024-03-09 06:48:15 +00:00
|
|
|
nuxt.hook('pages:extend', (pages) => {
|
2024-02-07 10:00:19 +00:00
|
|
|
pages.push({
|
|
|
|
path: '/manual-redirect',
|
2024-03-09 06:48:15 +00:00
|
|
|
redirect: '/'
|
2024-02-07 10:00:19 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2022-10-08 14:18:57 +00:00
|
|
|
function (_options, nuxt) {
|
|
|
|
const routesToDuplicate = ['/async-parent', '/fixed-keyed-child-parent', '/keyed-child-parent', '/with-layout', '/with-layout2']
|
2022-11-03 20:22:20 +00:00
|
|
|
const stripLayout = (page: NuxtPage): NuxtPage => ({
|
2022-10-08 14:18:57 +00:00
|
|
|
...page,
|
|
|
|
children: page.children?.map(child => stripLayout(child)),
|
|
|
|
name: 'internal-' + page.name,
|
|
|
|
path: withoutLeadingSlash(page.path),
|
|
|
|
meta: {
|
2023-11-09 17:01:13 +00:00
|
|
|
...page.meta,
|
2022-10-08 14:18:57 +00:00
|
|
|
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
|
|
|
|
})
|
2023-03-07 09:30:05 +00:00
|
|
|
},
|
2023-03-19 23:16:13 +00:00
|
|
|
// To test falsy module values
|
|
|
|
undefined
|
2022-09-12 15:14:11 +00:00
|
|
|
],
|
2023-02-09 08:26:23 +00:00
|
|
|
vite: {
|
2023-10-22 08:08:43 +00:00
|
|
|
logLevel: 'silent',
|
|
|
|
build: {
|
|
|
|
assetsInlineLimit: 100 // keep SVG as assets URL
|
|
|
|
}
|
2023-02-09 08:26:23 +00:00
|
|
|
},
|
2023-04-19 21:02:15 +00:00
|
|
|
telemetry: false, // for testing telemetry types - it is auto-disabled in tests
|
2022-02-17 14:23:55 +00:00
|
|
|
hooks: {
|
2023-05-30 11:53:04 +00:00
|
|
|
'webpack:config' (configs) {
|
2023-10-10 11:14:55 +00:00
|
|
|
// in order to test bigint serialization we need to set target to a more modern one
|
2023-05-30 11:53:04 +00:00
|
|
|
for (const config of configs) {
|
|
|
|
const esbuildRules = config.module!.rules!.filter(
|
|
|
|
rule => typeof rule === 'object' && rule && 'loader' in rule && rule.loader === 'esbuild-loader'
|
|
|
|
)
|
|
|
|
for (const rule of esbuildRules) {
|
|
|
|
if (typeof rule === 'object' && typeof rule.options === 'object') {
|
|
|
|
rule.options.target = 'es2022'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-02-17 14:23:55 +00:00
|
|
|
'modules:done' () {
|
|
|
|
addComponent({
|
|
|
|
name: 'CustomComponent',
|
|
|
|
export: 'namedExport',
|
|
|
|
filePath: '~/other-components-folder/named-export'
|
|
|
|
})
|
2023-01-16 16:04:16 +00:00
|
|
|
},
|
2023-08-09 11:19:00 +00:00
|
|
|
'components:extend' (components) {
|
|
|
|
for (const comp of components) {
|
|
|
|
if (comp.pascalName === 'GlobalSync') {
|
|
|
|
comp.global = 'sync'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-01-16 16:04:16 +00:00
|
|
|
'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()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-02-17 14:23:55 +00:00
|
|
|
}
|
2022-03-17 22:17:59 +00:00
|
|
|
},
|
2023-02-16 12:45:08 +00:00
|
|
|
vue: {
|
|
|
|
compilerOptions: {
|
|
|
|
isCustomElement: (tag) => {
|
|
|
|
return tag === 'custom-component'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-12-25 14:03:29 +00:00
|
|
|
features: {
|
2024-03-09 06:48:15 +00:00
|
|
|
inlineStyles: id => !!id && !id.includes('assets.vue')
|
2023-12-25 14:03:29 +00:00
|
|
|
},
|
2022-03-17 22:17:59 +00:00
|
|
|
experimental: {
|
2023-05-09 17:08:07 +00:00
|
|
|
typedPages: true,
|
2023-04-07 13:10:35 +00:00
|
|
|
polyfillVueUseHead: true,
|
2023-04-03 10:39:01 +00:00
|
|
|
respectNoSSRHeader: true,
|
2023-03-08 21:13:06 +00:00
|
|
|
clientFallback: true,
|
2023-03-08 12:17:22 +00:00
|
|
|
restoreState: true,
|
2024-01-18 16:09:27 +00:00
|
|
|
clientNodeCompat: true,
|
2023-12-19 12:21:29 +00:00
|
|
|
componentIslands: {
|
2024-03-06 15:26:19 +00:00
|
|
|
selectiveClient: 'deep'
|
2023-12-19 12:21:29 +00:00
|
|
|
},
|
2022-11-15 16:27:34 +00:00
|
|
|
treeshakeClientOnly: true,
|
2023-08-08 09:45:37 +00:00
|
|
|
asyncContext: process.env.TEST_CONTEXT === 'async',
|
2023-09-30 09:58:55 +00:00
|
|
|
appManifest: process.env.TEST_MANIFEST !== 'manifest-off',
|
2023-08-23 20:38:17 +00:00
|
|
|
headNext: true,
|
|
|
|
inlineRouteRules: true
|
2022-08-17 15:23:13 +00:00
|
|
|
},
|
|
|
|
appConfig: {
|
|
|
|
fromNuxtConfig: true,
|
|
|
|
nested: {
|
|
|
|
val: 1
|
|
|
|
}
|
2022-02-17 14:23:55 +00:00
|
|
|
}
|
2021-07-15 09:38:06 +00:00
|
|
|
})
|