forked from misskey-dev/misskey-hub-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nuxt.config.ts
218 lines (207 loc) · 5.53 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
// https://nuxt.com/docs/api/configuration/nuxt-config
import yaml from '@rollup/plugin-yaml';
import svgLoader from 'vite-svg-loader';
import { watch as fsWatch } from 'fs';
import { genApiTranslationFiles } from './scripts/gen-api-translations';
import { getOldHubRedirects } from './scripts/get-old-hub-redirects';
import { genLocalesJson } from './scripts/gen-locales';
import { getStaticEndpoints } from './scripts/get-static-endpoints';
import { locales } from './assets/data/locales';
import type { NuxtConfig } from 'nuxt/schema';
import { fetchCrowdinMembers } from './scripts/fetch-crowdin';
import { genSpaLoadingTemplate } from './scripts/gen-spa-loading-template';
// 公開時のドメイン(末尾スラッシュなし)
const baseUrl =
process.env.NODE_ENV == 'development'
? 'http://localhost:3000'
: 'https://misskey-hub.net';
// リポジトリURL(末尾スラッシュなし)
const repositoryUrl = 'https://github.com/misskey-dev/misskey-hub-next';
// 言語定義は /assets/data/locales.ts に移動しました
function getRouteRules(): NuxtConfig['routeRules'] | undefined {
if (process.env.NODE_ENV === 'development' || process.prerender) return undefined;
// 言語ごとに割り当てる必要のないRouteRules
const staticRules: NuxtConfig['routeRules'] = {
'/ja/blog/**': { isr: true },
'/ns/': { prerender: true },
};
// それぞれの言語について割り当てる必要のあるRouteRules
const localeBasedRules: NuxtConfig['routeRules'] = {
// リリースページはどうせアクセス集中するので先に作っておく
'/docs/releases/': { prerender: true },
'/docs/**': { isr: true },
};
// 静的ページをすべて追加
getStaticEndpoints().forEach((route) => {
if (!route.includes('ns')) {
localeBasedRules[route] = { prerender: true };
staticRules[route] = { prerender: true };
}
});
// 言語ごとにすべて割り当てていく
const _localeBasedRules: NuxtConfig['routeRules'] = {};
const localeCodes = locales.map((v) => v.code);
Object.keys(localeBasedRules).forEach((route) => {
localeCodes.forEach((code) => {
_localeBasedRules[`/${code}${route}`] = localeBasedRules[route];
});
})
return {
...staticRules,
..._localeBasedRules,
...((process.env.VERCEL !== '1') ? getOldHubRedirects('nitro') : {}),
};
}
export default defineNuxtConfig({
runtimeConfig: {
public: {
baseUrl,
repositoryUrl,
locales,
},
CROWDIN_INTG_API: process.env.CROWDIN_INTG_API,
},
css: [
"github-markdown-css/github-markdown.css",
"@/assets/css/nprogress.css",
"@/assets/css/tailwind.css",
"@/assets/css/mfm.scss",
"@/assets/css/bootstrap-forms.scss",
],
modules: [
'@nuxt/content',
'@nuxtjs/i18n',
'@nuxtjs/color-mode',
],
app: {
head: {
link: [
{ rel: 'stylesheet', href: '/fonts/fonts.css' },
{ rel: 'apple-touch-icon', href: '/img/icons/apple-touch-icon.png' },
{ rel: 'shortcut icon', type: 'image/vnd.microsoft.icon', href: '/favicon.ico' },
{ rel: 'icon', type: 'image/vnd.microsoft.icon', href: '/favicon.ico' },
{ rel: 'me', href: 'https://misskey.io/@misskey_hub_deploy' },
{ rel: 'me', href: 'https://mastodon.social/@misskey' },
],
meta: [
{ name: 'twitter:card', content: 'summary_large_image' },
]
},
},
content: {
markdown: {
remarkPlugins: [ 'misskey-hub-markdown-fixer' ],
},
navigation: {
fields: [
'date',
'description',
]
},
highlight: {
theme: {
// Default theme (same as single string)
default: 'catppuccin-latte',
// Theme used if `html.dark`
dark: 'one-dark-pro',
},
langs: [
'json', 'js', 'ts', 'html', 'css', 'vue', 'shell', 'mdc', 'md', 'yaml', 'jsx',
'ini', 'sql', 'yml', 'nginx', 'bash',
],
},
},
i18n: {
baseUrl,
vueI18n: './i18n.config.ts',
locales,
lazy: true,
langDir: 'locales_dist',
defaultLocale: 'ja',
// ▼ Defaultルートは、nitroプラグインでオーバーライドする
// リンクはuseGLocalePath(ラッパー)を使う
strategy: 'prefix_and_default',
trailingSlash: true,
},
colorMode: {
classSuffix: '',
},
postcss: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
devtools: { enabled: false },
alias: {
'bi': 'bootstrap-icons/icons',
},
vite: {
plugins: [
yaml(),
svgLoader({
defaultImport: 'component',
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
}
}
}
]
}
}),
],
},
vue: {
compilerOptions: {
isCustomElement: (tag) => tag.startsWith('model-viewer'),
},
},
nitro: {
// リダイレクトが多すぎてCloudflare Pagesのネイティブリダイレクトが使えないので静的モードに強制
preset: (process.env.CF_PAGES ? 'static' : undefined),
vercel: {
config: {
routes: [
...getOldHubRedirects('vercel'),
],
}
},
plugins: [
'@/server/plugins/appendComment.ts',
'@/server/plugins/i18nRedirector.ts',
],
prerender: {
failOnError: false,
}
},
hooks: {
'build:before': async () => {
genApiTranslationFiles();
await Promise.all([
genLocalesJson().then(() => {
if (process.env.NODE_ENV === 'development') {
fsWatch('./locales/', (ev, filename) => {
if (filename && filename.endsWith('.yml')) {
genLocalesJson();
}
});
}
}),
genSpaLoadingTemplate(),
fetchCrowdinMembers(),
]);
},
},
features: {
inlineStyles: false,
},
experimental: {
componentIslands: true,
},
routeRules: getRouteRules(),
});