2022-09-12 15:14:11 +00:00
|
|
|
import { addComponent, addVitePlugin, addWebpackPlugin } from '@nuxt/kit'
|
2022-10-08 14:18:57 +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({
|
2023-03-11 21:16:01 +00:00
|
|
|
typescript: {
|
|
|
|
strict: true,
|
|
|
|
tsConfig: {
|
|
|
|
compilerOptions: {
|
|
|
|
// TODO: For testing (future) support for Node16-style module resolution.
|
|
|
|
// See https://github.com/nuxt/nuxt/issues/18426 and https://github.com/nuxt/nuxt/pull/18431
|
|
|
|
// moduleResolution: 'Node16'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-08-07 09:53:53 +00:00
|
|
|
app: {
|
2022-10-24 15:23:49 +00:00
|
|
|
pageTransition: true,
|
|
|
|
layoutTransition: true,
|
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' }
|
|
|
|
]
|
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-01 10:05:02 +00:00
|
|
|
theme: './extends/bar',
|
2022-09-03 13:03:30 +00:00
|
|
|
css: ['~/assets/global.css'],
|
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: {
|
2022-10-17 14:15:59 +00:00
|
|
|
routeRules: {
|
2022-10-11 16:03:52 +00:00
|
|
|
'/route-rules/spa': { ssr: false }
|
|
|
|
},
|
2022-09-10 13:57:16 +00:00
|
|
|
output: { dir: process.env.NITRO_OUTPUT_DIR },
|
|
|
|
prerender: {
|
|
|
|
routes: [
|
|
|
|
'/random/a',
|
|
|
|
'/random/b',
|
|
|
|
'/random/c'
|
|
|
|
]
|
|
|
|
}
|
2021-10-02 20:30:20 +00:00
|
|
|
},
|
2023-03-07 21:06:15 +00:00
|
|
|
optimization: {
|
|
|
|
keyedComposables: [
|
|
|
|
{
|
|
|
|
name: 'useKeyedComposable',
|
|
|
|
argumentLength: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2022-11-16 02:26:35 +00:00
|
|
|
runtimeConfig: {
|
2023-02-06 23:27:35 +00:00
|
|
|
baseURL: '',
|
|
|
|
baseAPIToken: '',
|
2022-11-16 02:26:35 +00:00
|
|
|
privateConfig: 'secret_key',
|
|
|
|
public: {
|
2023-02-10 07:36:10 +00:00
|
|
|
ids: [1, 2, 3],
|
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-01-21 16:55:44 +00:00
|
|
|
[
|
|
|
|
'~/modules/example',
|
|
|
|
{
|
|
|
|
typeTest (val) {
|
|
|
|
// @ts-expect-error module type defines val as boolean
|
|
|
|
const b: string = val
|
|
|
|
return !!b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
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 }' }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
addVitePlugin(plugin.vite())
|
|
|
|
addWebpackPlugin(plugin.webpack())
|
2022-10-08 14:18:57 +00:00
|
|
|
},
|
2023-04-07 10:34:35 +00:00
|
|
|
function (_options, nuxt) {
|
|
|
|
// TODO: support directly via object syntax plugins: https://github.com/nuxt/nuxt/issues/14628
|
|
|
|
nuxt.hook('modules:done', () => {
|
|
|
|
nuxt.options.plugins.unshift('~/plugins/custom-type-registration')
|
|
|
|
})
|
|
|
|
},
|
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: {
|
|
|
|
...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
|
|
|
|
})
|
2023-03-07 09:30:05 +00:00
|
|
|
},
|
|
|
|
function (_, nuxt) {
|
|
|
|
nuxt.options.optimization.treeShake.composables.server[nuxt.options.rootDir] = ['useClientOnlyComposable', 'setTitleToPink']
|
|
|
|
nuxt.options.optimization.treeShake.composables.client[nuxt.options.rootDir] = ['useServerOnlyComposable']
|
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: {
|
|
|
|
logLevel: 'silent'
|
|
|
|
},
|
2022-02-17 14:23:55 +00:00
|
|
|
hooks: {
|
2022-09-22 13:50:40 +00:00
|
|
|
'prepare:types' ({ tsConfig }) {
|
2022-11-03 20:22:20 +00:00
|
|
|
tsConfig.include = tsConfig.include!.filter(i => i !== '../../../../**/*')
|
2022-09-22 13:50:40 +00:00
|
|
|
},
|
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
|
|
|
},
|
|
|
|
'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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-17 22:17:59 +00:00
|
|
|
experimental: {
|
2023-04-07 13:10:35 +00:00
|
|
|
polyfillVueUseHead: true,
|
2023-04-07 10:34:35 +00:00
|
|
|
renderJsonPayloads: 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,
|
2022-11-03 20:22:20 +00:00
|
|
|
inlineSSRStyles: id => !!id && !id.includes('assets.vue'),
|
2022-11-24 12:24:14 +00:00
|
|
|
componentIslands: true,
|
2022-07-17 13:13:04 +00:00
|
|
|
reactivityTransform: true,
|
2022-11-15 16:27:34 +00:00
|
|
|
treeshakeClientOnly: true,
|
2023-03-04 14:39:26 +00:00
|
|
|
payloadExtraction: 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
|
|
|
})
|