jointrashposs/nuxt.config.ts

202 lines
5.0 KiB
TypeScript
Raw Permalink Normal View History

2023-07-08 10:36:02 +02:00
// https://nuxt.com/docs/api/configuration/nuxt-config
import yaml from '@rollup/plugin-yaml';
2023-07-08 10:36:02 +02:00
import svgLoader from 'vite-svg-loader';
import { readFileSync, watch as fsWatch } from 'fs';
2023-07-17 18:44:06 +02:00
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';
2023-11-30 14:43:05 +01:00
import type { NuxtConfig } from 'nuxt/schema';
2023-12-24 06:47:17 +01:00
import { fetchCrowdinMembers } from './scripts/fetch-crowdin';
2023-07-08 10:36:02 +02:00
2023-07-10 19:54:13 +02:00
// 公開時のドメイン(末尾スラッシュなし)
const baseUrl =
process.env.NODE_ENV == 'development'
? 'http://localhost:3000'
: 'https://misskey-hub.net';
2023-07-10 19:54:13 +02:00
2023-12-18 09:43:48 +01:00
// リポジトリURL末尾スラッシュなし
const repositoryUrl = 'https://github.com/misskey-dev/misskey-hub-next';
// 言語定義は /assets/data/locales.ts に移動しました
2023-07-11 19:19:32 +02:00
2024-01-28 04:41:15 +01:00
function getRouteRules(): NuxtConfig['routeRules'] | undefined {
if (process.env.NODE_ENV === 'development' || process.prerender) return undefined;
2023-11-30 14:43:05 +01:00
// 言語ごとに割り当てる必要のないRouteRules
const staticRules: NuxtConfig['routeRules'] = {
'/ja/blog/**': { isr: true },
'/ns/': { prerender: true },
2023-11-30 14:43:05 +01:00
};
// それぞれの言語について割り当てる必要のあるRouteRules
const localeBasedRules: NuxtConfig['routeRules'] = {
2023-12-02 11:19:15 +01:00
// リリースページはどうせアクセス集中するので先に作っておく
'/docs/releases/': { prerender: true },
2023-11-30 14:43:05 +01:00
'/docs/**': { isr: true },
};
// 静的ページをすべて追加
getStaticEndpoints().forEach((route) => {
if (!route.includes('ns')) {
localeBasedRules[route] = { prerender: true };
staticRules[route] = { prerender: true };
}
});
2023-11-30 14:43:05 +01:00
// 言語ごとにすべて割り当てていく
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,
2023-12-23 17:05:41 +01:00
...((process.env.VERCEL !== '1') ? getOldHubRedirects('nitro') : {}),
2023-11-30 14:43:05 +01:00
};
}
2023-07-08 10:36:02 +02:00
export default defineNuxtConfig({
2023-07-10 19:54:13 +02:00
runtimeConfig: {
public: {
baseUrl,
2023-12-18 09:43:48 +01:00
repositoryUrl,
2023-11-25 17:48:16 +01:00
locales,
2023-12-24 06:47:17 +01:00
},
CROWDIN_INTG_API: process.env.CROWDIN_INTG_API,
2023-07-10 19:54:13 +02:00
},
2023-07-08 10:36:02 +02:00
css: [
2023-07-10 19:54:13 +02:00
"github-markdown-css/github-markdown.css",
2023-10-29 14:02:27 +01:00
"@/assets/css/nprogress.css",
2023-07-08 10:36:02 +02:00
"@/assets/css/tailwind.css",
2023-12-21 11:01:37 +01:00
"@/assets/css/mfm.scss",
2023-07-09 11:58:53 +02:00
"@/assets/css/bootstrap-forms.scss",
2023-07-08 10:36:02 +02:00
],
modules: [
'@nuxt/content',
'@nuxtjs/i18n',
2023-07-08 19:23:27 +02:00
'@nuxtjs/color-mode',
2023-07-08 10:36:02 +02:00
],
app: {
head: {
link: [
{ rel: 'stylesheet', href: '/fonts/fonts.css' },
2023-12-04 07:50:06 +01:00
{ rel: 'apple-touch-icon', href: '/img/icons/apple-touch-icon.png' },
2023-12-01 17:20:08 +01:00
{ rel: 'shortcut icon', type: 'image/vnd.microsoft.icon', href: '/favicon.ico' },
{ rel: 'icon', type: 'image/vnd.microsoft.icon', href: '/favicon.ico' },
2023-12-22 12:28:30 +01:00
{ rel: 'me', href: 'https://misskey.io/@misskey_hub_deploy' },
2023-07-08 10:36:02 +02:00
],
2023-12-01 17:20:08 +01:00
meta: [
{ name: 'twitter:card', content: 'summary_large_image' },
]
2023-07-08 10:36:02 +02:00
},
},
2023-07-10 19:54:13 +02:00
content: {
navigation: {
fields: [
'date',
'description',
2023-07-10 19:54:13 +02:00
]
2023-07-17 18:44:06 +02:00
},
highlight: {
theme: {
// Default theme (same as single string)
default: 'github-light',
// Theme used if `html.dark`
dark: 'github-dark',
},
preload: [
'ini', 'sql', 'yml', 'nginx', 'bash',
JSON.parse(readFileSync('./node_modules/aiscript-vscode/aiscript/syntaxes/aiscript.tmLanguage.json', { encoding: 'utf-8' })),
],
2023-07-17 18:44:06 +02:00
},
2023-07-10 19:54:13 +02:00
},
2023-07-08 10:36:02 +02:00
i18n: {
2023-07-10 19:54:13 +02:00
baseUrl,
2023-07-08 10:36:02 +02:00
vueI18n: './i18n.config.ts',
2023-07-11 19:19:32 +02:00
locales,
lazy: true,
langDir: 'locales_dist',
2023-07-08 10:36:02 +02:00
defaultLocale: 'ja',
// ▼ Defaultルートは、nitroプラグインでオーバーライドする
//   リンクはuseGLocalePathラッパーを使う
strategy: 'prefix_and_default',
trailingSlash: true,
2023-07-08 10:36:02 +02:00
},
2023-07-08 19:23:27 +02:00
colorMode: {
classSuffix: '',
},
2023-07-08 10:36:02 +02:00
postcss: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
devtools: { enabled: false },
2023-07-08 10:36:02 +02:00
alias: {
'bi': 'bootstrap-icons/icons',
},
vite: {
plugins: [
yaml(),
2023-07-08 10:36:02 +02:00
svgLoader({
defaultImport: 'component',
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
}
}
}
]
}
}),
],
2023-07-08 10:36:02 +02:00
},
nitro: {
2023-12-12 14:46:53 +01:00
vercel: {
config: {
routes: [
...getOldHubRedirects('vercel'),
2023-12-12 14:46:53 +01:00
],
}
},
2023-07-08 10:36:02 +02:00
plugins: [
'@/server/plugins/appendComment.ts',
2023-09-29 13:30:27 +02:00
'@/server/plugins/i18nRedirector.ts',
2023-07-08 10:36:02 +02:00
],
2024-01-28 04:41:15 +01:00
prerender: {
failOnError: false,
}
2023-07-13 18:27:48 +02:00
},
2023-07-17 18:44:06 +02:00
hooks: {
2023-12-24 06:47:17 +01:00
'build:before': async (...args) => {
genApiTranslationFiles(...args);
genLocalesJson(...args);
if (process.env.NODE_ENV === 'development') {
fsWatch('./locales/', (ev, filename) => {
if (filename && filename.endsWith('.yml')) {
genLocalesJson(...args);
}
});
}
2023-12-24 06:47:17 +01:00
await fetchCrowdinMembers(...args);
},
2023-07-17 18:44:06 +02:00
},
2023-12-27 11:49:37 +01:00
features: {
inlineStyles: false,
},
2023-07-13 18:27:48 +02:00
experimental: {
2023-09-28 12:29:11 +02:00
componentIslands: true,
2023-07-13 18:27:48 +02:00
},
2023-11-30 14:43:05 +01:00
routeRules: getRouteRules(),
});