-
Notifications
You must be signed in to change notification settings - Fork 2
/
nuxt.config.ts
233 lines (227 loc) · 7.91 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import svgLoader from 'vite-svg-loader'
import type { NuxtPlugin } from '@nuxt/schema'
import { version } from './package.json'
import { I18N_DEFAULT_LOCALE, I18N_LOCALES } from './i18n.config'
const isDev = process.env.NODE_ENV === 'development'
const isGenerate = process.argv.includes('generate')
const isGenerateMaintenance = isGenerate && process.argv.includes('--maintenance')
const isNuxtStories = process.env.NUXT_STORIES === '1'
const plugins: (NuxtPlugin | string)[] = []
if (isNuxtStories) {
plugins.push('./plugins/stories/msw.ts')
}
export default defineNuxtConfig({
modules: [
'@nuxtjs/svg-sprite',
// the Intervention Request provider module has to be registered before the Nuxt image module
// @see https://github.com/rezozero/intervention-request-provider?tab=readme-ov-file#installation
'@rezo-zero/intervention-request-provider',
'@nuxt/image',
'@rezo-zero/nuxt-stories',
'@nuxtjs/i18n',
'@nuxtjs/sitemap',
'@vueuse/nuxt',
'@rezo-zero/nuxt-cache-control',
'@nuxt/eslint',
'@nuxtjs/robots',
],
plugins,
// Don't use layer for now
// extends: ['github:rezozero/nuxt-layer#v0.1.6'],
components: [
'~/components/atoms',
'~/components/molecules',
'~/components/organisms',
{ path: '~/components/blocks/', global: true },
],
devtools: { enabled: true },
css: ['~/assets/scss/main.scss'],
runtimeConfig: {
public: {
version,
site: {
url: 'http://localhost:3000',
environment: 'development',
},
api: {
url: '',
endpointPrefix: '/api',
documentPath: '/files',
},
interventionRequest: {
baseUrl: '',
noProcessBaseUrl: '',
},
matomo: {
url: '',
containerID: '',
},
googleTagManager: {
id: '',
},
recaptcha: {
siteKey: '',
version: 3,
},
sentry: {
dsn: '',
},
cacheControl: {
maxAge: 60 * 60, // 1 hour
staleWhileRevalidate: 60 * 2, // 2 minutes
public: true,
},
cacheTags: {
key: 'cache-tags',
},
},
},
ignore: [
...(isGenerateMaintenance ? ['server/api/**'] : []),
isGenerateMaintenance || isDev ? '!**/maintenance.vue' : undefined, // except maintenance
],
features: {
noScripts: isGenerateMaintenance, // maintenance page does not need JS
},
experimental: {
asyncContext: true,
appManifest: false, // We don't need client route rules for now, and Nuxt makes an extra request to get them.
},
compatibilityDate: '2024-07-24',
nitro: {
prerender: {
autoSubfolderIndex: false,
crawlLinks: false,
failOnError: true,
ignore: [
(route) => {
if (!isGenerateMaintenance) return false
return !route.includes('maintenance')
},
],
},
routeRules: {
'/**': {
headers: {
// https://web.dev/articles/floc?hl=fr#can_websites_opt_out_of_being_included_in_the_floc_computation
'Permissions-Policy': 'interest-cohort=()',
// Hardening client security policies
// https://developer.mozilla.org/fr/docs/Web/HTTP/CSP
'Content-Security-Policy': [
// Only allows these iframe origins
'frame-src \'self\' *.youtube.com *.youtube-nocookie.com *.vimeo.com *.instagram.com *.soundcloud.com *.google.com *.deezer.com *.spotify.com',
// Only allows these script origins
// "script-src 'self' 'unsafe-inline' *.google.com *.googleapis.com *.gstatic.com",
// Only allows these images origins
// "img-src 'self' 'unsafe-inline' *.googleapis.com *.gstatic.com",
].join('; '),
},
},
'/maintenance': {
prerender: isGenerateMaintenance,
headers: {
'X-Robots-Tag': 'noindex',
},
},
// Auto generated page by svgSprite module
'/_icons': {
headers: {
// Do not index the page and remove it from sitemap
'X-Robots-Tag': 'noindex',
},
},
},
},
vite: {
build: {
// If the generated svg-sprite file is under 4kb, the build process converts it to an inlined base64 file,
// which breaks the use of icons.
assetsInlineLimit: 0,
},
css: {
preprocessorOptions: {
scss: {
quietDeps: true,
// For now, just silence the deprecation warning.
// But we have to use Dart Sass modern API https://sass-lang.com/documentation/breaking-changes/legacy-js-api/ soon.
// Vite 5.x uses the legacy API as default https://vitejs.dev/config/shared-options.html#css-preprocessoroptions
// Probably for best performance we should use `api: "modern-compiler"` and `sass-embedded` package.
// Waiting on Vite fixing the missing sourcemap files https://github.com/vitejs/vite/pull/18113 warning.
silenceDeprecations: ['legacy-js-api'],
},
},
},
plugins: [
// https://github.com/jpkleemans/vite-svg-loader?tab=readme-ov-file#setup
svgLoader({
defaultImport: 'url',
}),
],
},
// https://eslint.nuxt.com/packages/module
eslint: {
config: {
stylistic: {
indent: 4,
},
},
},
// https://v8.i18n.nuxtjs.org/getting-started/setup
i18n: {
strategy: 'prefix_except_default',
detectBrowserLanguage: false,
defaultLocale: I18N_DEFAULT_LOCALE,
locales: I18N_LOCALES.map(locale => ({
code: locale,
file: `nuxt.${locale}.json`,
})),
lazy: true,
langDir: 'assets/locales/',
compilation: {
// Message can contains HTML tag
strictMessage: false,
},
},
// https://image.nuxt.com/get-started/configuration
image: {
quality: 75,
screens: {
xs: 375, // override nuxt/img sizes to match our breakpoints
sm: 480, // override
vl: 1280, // override
xl: 1440, // override
xxl: 1600, // override
hd: 1920, // additional size
qhd: 2500, // additional size
},
// @ts-expect-error not working with [1]
densities: '1',
presets: {
default: {
sizes: 'xs:100vw md:100vw lg:100vw vl:100vw xl:100vw hd:100vw qhd:100vw',
},
},
},
// https://nuxtseo.com/robots/api/config
robots: {
allow: ['/'],
disallow: ['/rz-admin', '/maintenance', '/_icons', '/api'],
},
// https://www.nuxtseo.com/sitemap/getting-started/installation
sitemap: {
enabled: !isGenerateMaintenance,
sources: ['/api/sitemap'],
},
// https://github.com/rezozero/nuxt-stories
stories: {
pattern: [
'**/*.stories.vue',
'!playground', // exclude layer stories
],
},
// https://github.com/nuxt-modules/svg-sprite#options
svgSprite: {
input: '~/assets/images/icons',
output: '~/assets/images/sprites',
},
})