jointrashposs/nuxt.config.ts

181 lines
4.6 KiB
TypeScript
Raw 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 } from 'fs';
2023-07-17 18:44:06 +02:00
import { genApiTranslationFiles } from './scripts/gen-api-translations';
2023-11-06 17:21:48 +01:00
import type { LocaleObject } from '@nuxtjs/i18n/dist/runtime/composables';
import { genLocalesJson } from './scripts/gen-locales';
import { getStaticEndpoints } from './scripts/get-static-endpoints';
2023-11-30 14:43:05 +01:00
import type { NuxtConfig } from 'nuxt/schema';
2023-07-08 10:36:02 +02:00
2023-07-10 19:54:13 +02:00
// 公開時のドメイン(末尾スラッシュなし)
2023-12-02 05:42:07 +01:00
const baseUrl = 'https://misskey-hub-next.vercel.app';
2023-07-10 19:54:13 +02:00
2023-11-06 17:21:48 +01:00
// 言語定義
2023-11-12 05:21:23 +01:00
export const localesConst = [
{ files: [ 'ja-JP.json' ], code: 'ja', iso: 'ja-JP', name: '日本語' },
{ files: [ 'en-US.json' ], code: 'en', iso: 'en-US', name: 'English' },
{ files: [ 'id-ID.json' ], code: 'id', iso: 'id-ID', name: 'Bahasa Indonesia' },
{ files: [ 'ko-KR.json' ], code: 'ko', iso: 'ko-KR', name: '한국어' },
{ files: [ 'it-IT.json' ], code: 'it', iso: 'it-IT', name: 'Italiano' },
{ files: [ 'pl-PL.json' ], code: 'pl', iso: 'pl-PL', name: 'Polski' },
{ files: [ 'fr-FR.json' ], code: 'fr', iso: 'fr-FR', name: 'Français' },
{ files: [ 'zh-CN.json' ], code: 'cn', iso: 'zh-CN', name: '简体中文' },
{ files: [ 'zh-TW.json' ], code: 'tw', iso: 'zh-TW', name: '繁体中文' },
2023-11-12 05:21:23 +01:00
] as const;
export type LocaleCodes = typeof localesConst[number]['code'];
export const locales = localesConst as unknown as LocaleObject[];
2023-07-11 19:19:32 +02:00
2023-11-30 14:43:05 +01:00
function getRouteRules(): NuxtConfig['routeRules'] {
// 言語ごとに割り当てる必要のない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'] = {
'/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-07-08 10:36:02 +02:00
export default defineNuxtConfig({
2023-07-10 19:54:13 +02:00
runtimeConfig: {
public: {
baseUrl,
2023-11-25 17:48:16 +01:00
locales,
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-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-01 17:20:08 +01:00
{ rel: 'apple-touch-icon', href: '/img/icon/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' },
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',
strategy: 'prefix',
2023-09-29 13:30:27 +02:00
detectBrowserLanguage: {
fallbackLocale: 'ja',
},
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: {},
},
},
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: {
preset: 'vercel',
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
],
2023-07-13 18:27:48 +02:00
},
2023-07-17 18:44:06 +02:00
hooks: {
'build:before': (...args) => {
genApiTranslationFiles(...args);
genLocalesJson(...args);
},
2023-07-17 18:44:06 +02:00
},
2023-07-13 18:27:48 +02:00
experimental: {
inlineSSRStyles: false,
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(),
});