-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.ts
144 lines (129 loc) · 4.21 KB
/
module.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
import {
addComponentsDir,
addImports,
addImportsDir,
addPlugin,
addRouteMiddleware,
createResolver,
defineNuxtModule,
extendPages,
installModule,
} from '@nuxt/kit'
import { name, version } from '../package.json'
import type { CSSOptions } from 'vite'
import type { ViteConfig } from '@nuxt/schema'
import { defu } from 'defu'
export const CONFIG_KEY = 'typo3'
export interface ModuleOptions {
// TYPO3 Headless Backend information
api: {
// URL of the TYPO3 Backend
baseUrl?: string
// Type number of the initial data, only required if changed in backend
initialDataType?: number
}
// URL of the frontend project, used for page meta data
baseUrl: string
componentPrefix?: string
// UID from cookiebot, required if cookie consent banner should be shown
cookiebotUid?: string
// Path to SCSS Variables to override default values defined in runtime/assets/style/*.scss
// See playground assets/breakpoints.scss or assets/colors.scss for example
scssForwards?: string | string[]
}
export default defineNuxtModule<ModuleOptions>({
defaults: {
api: {
baseUrl: '',
initialDataType: 834,
},
baseUrl: '',
cookiebotUid: '',
},
meta: {
configKey: CONFIG_KEY,
name,
version,
},
async setup(options, nuxt) {
const resolver = createResolver(import.meta.url)
nuxt.options.runtimeConfig.public[CONFIG_KEY] = defu(
nuxt.options.runtimeConfig.public[CONFIG_KEY],
options,
)
nuxt.hook('prepare:types', (options) => {
options.references.push(
{
path: resolver.resolve('runtime/types/hooks.d.ts'),
},
{
path: resolver.resolve('runtime/types/schema.d.ts'),
},
)
})
options = nuxt.options.runtimeConfig.public[CONFIG_KEY]
if (options.scssForwards) {
const scssForwards =
typeof options.scssForwards === 'string'
? [options.scssForwards]
: options.scssForwards
const cssOptions: CSSOptions = {
preprocessorOptions: {
scss: {
additionalData: `${scssForwards
.map((value) => `@forward "${value}"`)
.join(';')};`.concat(
nuxt.options.vite.css?.preprocessorOptions?.scss
.additionalData ?? '',
),
},
},
}
nuxt.options.vite.css = defu(
cssOptions,
nuxt.options.vite.css ?? {},
)
}
const viteConfig: ViteConfig = {
// https://github.com/vitejs/vite/issues/9220
optimizeDeps: {
include: ['yup'],
},
}
nuxt.options.vite = defu(viteConfig, nuxt.options.vite)
nuxt.options.pages = true
nuxt.options.alias['#nuxt-typo3'] = resolver.resolve('runtime')
nuxt.options.css.unshift(
resolver.resolve('runtime/assets/styles/global.scss'),
)
await installModule('@remindgmbh/nuxt-logger')
addImportsDir(resolver.resolve('runtime/composables/**/*'))
addImports({
as: 'T3Model',
from: resolver.resolve('runtime/models'),
name: '*',
})
addComponentsDir({
path: resolver.resolve('runtime/components'),
pathPrefix: false,
})
addPlugin({
src: resolver.resolve('runtime/plugins/cookiebot'),
})
addPlugin({
src: resolver.resolve('runtime/plugins/i18n'),
})
addRouteMiddleware({
global: true,
name: 't3-data',
path: resolver.resolve('runtime/middleware/data.global'),
})
extendPages((pages) => {
pages.push({
file: resolver.resolve('runtime/pages/T3Page'),
name: 'T3Page',
path: '/:pathMatch(.*)*',
})
})
},
})