This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
nuxt.config.ts
331 lines (316 loc) · 8.77 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import path from "path"
import fs from "fs"
import pkg from "./package.json"
import locales from "./src/locales/scripts/valid-locales.json"
import { VIEWPORTS } from "./src/constants/screens"
import { isProd } from "./src/utils/node-env"
import { sentryConfig } from "./src/utils/sentry-config"
import { env } from "./src/utils/env"
import type http from "http"
import type { NuxtConfig } from "@nuxt/types"
import type { LocaleObject } from "@nuxtjs/i18n"
import type { IncomingMessage, NextFunction } from "connect"
/**
* The default metadata for the site. Can be extended and/or overwritten per page. And even in components!
* See the Nuxt.js docs for more info.
* {@link https://nuxtjs.org/guides/features/meta-tags-seo} Nuxt.js Docs
*/
const meta = [
{ charset: "utf-8" },
{
name: "viewport",
content: "width=device-width,initial-scale=1",
},
// By default, tell all robots not to index pages. Will be overwritten in the
// search, content and home pages.
{ hid: "robots", name: "robots", content: "noindex" },
{
vmid: "monetization",
name: "monetization",
content: "$ilp.uphold.com/edR8erBDbRyq",
},
{
hid: "theme-color",
name: "theme-color",
content: "#ffffff",
},
{
name: "description",
content:
"Search over 600 million free and openly licensed images, photos, audio, and other media types for reuse and remixing.",
},
{ hid: "og:title", name: "og:title", content: "Openverse" },
{
hid: "og:image",
name: "og:image",
content: "/openverse-default.jpg",
},
{
hid: "og:description",
name: "og:description",
content:
"Search over 600 million free and openly licensed images, photos, audio, and other media types for reuse and remixing.",
},
{ name: "twitter:card", content: "summary_large_image" },
{ name: "twitter:site", content: "@WPOpenverse" },
]
if (process.env.NODE_ENV === "production") {
meta.push({
// @ts-expect-error: 'http-equiv' isn't allowed here by Nuxt
"http-equiv": "Content-Security-Policy",
content: "upgrade-insecure-requests",
})
}
const favicons = [
// SVG favicon
{
rel: "icon",
href: "/openverse-logo.svg",
},
// SVG favicon for Safari
{
rel: "mask-icon",
href: "/opvenverse-logo.svg",
color: "#30272E",
},
// Fallback iPhone Icon
{
rel: "apple-touch-icon",
href: "/openverse-logo-180.png",
},
]
// Default html head
const head = {
title: "Openly Licensed Images, Audio and More | Openverse",
meta,
link: [
...favicons,
{
rel: "preconnect",
href: env.apiUrl,
crossorigin: "",
},
{
rel: "dns-prefetch",
href: env.apiUrl,
},
{
rel: "search",
type: "application/opensearchdescription+xml",
title: "Openverse",
href: "/opensearch.xml",
},
],
}
const baseProdName = process.env.CI ? "[name]" : "[contenthash:7]"
const filenames: NonNullable<NuxtConfig["build"]>["filenames"] = {
app: ({ isDev, isModern }) =>
isDev
? `[name]${isModern ? ".modern" : ""}.js`
: `${baseProdName}${isModern ? ".modern" : ""}.js`,
chunk: ({ isDev, isModern }) =>
isDev
? `[name]${isModern ? ".modern" : ""}.js`
: `${baseProdName}${isModern ? ".modern" : ""}.js`,
css: ({ isDev }) => (isDev ? "[name].css" : `css/${baseProdName}.css`),
img: ({ isDev }) =>
isDev ? "[path][name].[ext]" : `img/${baseProdName}.[ext]`,
font: ({ isDev }) =>
isDev ? "[path][name].[ext]" : `fonts/${baseProdName}.[ext]`,
video: ({ isDev }) =>
isDev ? "[path][name].[ext]" : `videos/${baseProdName}.[ext]`,
}
const openverseLocales = [
{
// unique identifier for the locale in Vue i18n
code: "en",
name: "English",
nativeName: "English",
// ISO code used for SEO purposes (html lang attribute)
iso: "en",
// wp_locale as found in GlotPress
wpLocale: "en_US",
file: "en.json",
},
...(locales ?? []),
].filter((l) => Boolean(l.iso)) as LocaleObject[]
const config: NuxtConfig = {
// eslint-disable-next-line no-undef
version: pkg.version, // used to purge cache :)
cache: {
pages: ["/"],
store: {
type: "memory", // 'redis' would be nice
max: 100,
ttl: process.env.MICROCACHE_DURATION || 60,
},
},
srcDir: "src/",
modern: "client",
server: {
port: process.env.PORT || 8443,
https: process.env.LOCAL_SSL
? {
key: fs.readFileSync(path.resolve(__dirname, "localhost+1-key.pem")),
cert: fs.readFileSync(path.resolve(__dirname, "localhost+1.pem")),
}
: undefined,
},
router: {
middleware: "middleware",
},
components: [
{ path: "~/components", extensions: ["vue"], pathPrefix: false },
],
plugins: [
"~/plugins/url-change.ts",
"~/plugins/migration-notice.ts",
"~/plugins/ua-parse.ts",
"~/plugins/focus-visible.client.ts",
"~/plugins/api-token.server.ts",
"~/plugins/sentry.ts",
],
css: ["~/assets/fonts.css", "~/styles/tailwind.css", "~/styles/accent.css"],
head,
env, // TODO: Replace with `publicRuntimeConfig`
privateRuntimeConfig: {
apiClientId: process.env.API_CLIENT_ID,
apiClientSecret: process.env.API_CLIENT_SECRET,
},
dev: !isProd,
buildModules: [
"@nuxt/typescript-build",
"@nuxtjs/composition-api/module",
"@nuxt/postcss8",
"@nuxtjs/style-resources",
"@nuxtjs/svg",
"@nuxtjs/eslint-module",
"@pinia/nuxt",
],
modules: [
"portal-vue/nuxt",
"@nuxtjs/i18n",
"@nuxtjs/redirect-module",
"@nuxtjs/sentry",
"cookie-universal-nuxt",
"~/modules/prometheus.ts",
// Sitemap must be last to ensure that even routes created by other modules are added
"@nuxtjs/sitemap",
],
serverMiddleware: [
{ path: "/healthcheck", handler: "~/server-middleware/healthcheck.js" },
{ path: "/robots.txt", handler: "~/server-middleware/robots.js" },
],
i18n: {
baseUrl: "https://openverse.org",
locales: openverseLocales,
lazy: true,
langDir: "locales",
defaultLocale: "en",
/**
* `detectBrowserLanguage` must be false to prevent nuxt/i18n from automatically
* setting the locale based on headers or the client-side `navigator` object.
*
* Such detection is handled at the parent level in WP.org.
*
* More info about the Nuxt i18n:
*
* - [detectBrowserLanguage](https://i18n.nuxtjs.org/options-reference/#detectbrowserlanguage)
* - [Browser language detection info](https://i18n.nuxtjs.org/browser-language-detection)
* */
detectBrowserLanguage: false,
vueI18n: "~/plugins/vue-i18n",
},
sitemap: {
hostname: "https://openverse.org",
i18n: {
locales: openverseLocales.map((l) => l.iso),
routesNameSeparator: "___",
},
},
/**
* Map the old route for /photos/_id page to /image/_id permanently to keep links working.
* See the redirect module for more info.
* {@link https://github.com/nuxt-community/redirect-module#usage}
*/
redirect: {
rules: [
{ from: "^/photos/(.*)$", to: "/image/$1", statusCode: 301 },
{ from: "/meta-search", to: "/about", statusCode: 301 },
{ from: "/external-sources", to: "/about", statusCode: 301 },
],
// If the URL cannot be decoded, we call next() to show the client-side error page.
onDecodeError: (
_error: Error,
_req: IncomingMessage,
_res: http.ServerResponse,
next: NextFunction
) => {
return next()
},
},
sentry: sentryConfig,
build: {
templates: [
{
src: "./nuxt-template-overrides/App.js",
dst: "App.js",
},
{
src: "./nuxt-template-overrides/index.js",
dst: "index.js",
},
],
filenames,
friendlyErrors: false,
postcss: {
plugins: {
tailwindcss: {},
autoprefixer: {},
"postcss-focus-visible": {},
},
},
extend(config, ctx) {
// Enables use of IDE debuggers
config.devtool = ctx.isClient ? "source-map" : "inline-source-map"
// Mitigates import errors for Pinia
config.module?.rules.push({
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto",
})
},
},
storybook: {
port: 6006, // standard port for Storybook
stories: ["~/**/*.stories.@(mdx|js)"],
addons: [
{
name: "@storybook/addon-essentials",
options: {
backgrounds: true,
viewport: true,
toolbars: true,
},
},
],
parameters: {
backgrounds: {
default: "White",
values: [
{ name: "White", value: "#ffffff" },
{ name: "Dark charcoal", value: "#30272e" },
],
},
options: {
storySort: {
order: ["Introduction", ["Openverse UI"], "Meta"],
},
},
viewport: {
viewports: VIEWPORTS,
},
},
},
}
export default config