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 63
/
Copy pathnuxt.config.ts
289 lines (276 loc) · 7.64 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
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 { NuxtConfig } from '@nuxt/types'
import type { LocaleObject } from '@nuxtjs/i18n'
/**
* 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',
},
// Tells Google to only crawl Openverse when iframed
{ hid: 'googlebot', name: 'googlebot', content: 'noindex,indexifembedded' },
{
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 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: [
{ src: '~/plugins/url-change' },
{ src: '~/plugins/migration-notice' },
{ src: '~/plugins/ua-parse' },
{ src: '~/plugins/focus-visible', mode: 'client' },
],
css: ['~/styles/tailwind.css', '~/assets/fonts.css', '~/styles/accent.css'],
head,
env,
dev: !isProd,
buildModules: [
'@nuxt/typescript-build',
'@nuxtjs/composition-api/module',
'@nuxt/postcss8',
'@nuxtjs/style-resources',
'@nuxtjs/svg',
'@nuxtjs/eslint-module',
'@pinia/nuxt',
],
// Load the scss variables into every component:
// No need to import them. Since the variables will not exist in the final build,
// this doesn't make the built files larger.
styleResources: {
scss: ['./styles/utilities/all.scss'],
},
modules: [
'@nuxtjs/i18n',
'@nuxtjs/redirect-module',
'@nuxtjs/sentry',
'@nuxtjs/sitemap',
],
serverMiddleware: [
{ path: '/healthcheck', handler: '~/server-middleware/healthcheck.js' },
],
i18n: {
locales: [
{
// unique identifier for the locale in Vue i18n
code: 'en',
name: '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[],
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',
},
/**
* 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: [{ from: '^/photos/(.*)$', to: '/image/$1', statusCode: 301 }],
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: false,
viewport: true,
toolbars: true,
},
},
],
parameters: {
options: {
storySort: {
order: ['Introduction', ['Openverse UI']],
},
},
viewport: {
viewports: VIEWPORTS,
},
},
},
}
export default config