2023-12-07 23:22:08 +00:00
|
|
|
import dns from 'dns';
|
2024-01-29 12:39:34 +00:00
|
|
|
import { readFile } from 'node:fs/promises';
|
2024-07-06 02:46:43 +00:00
|
|
|
import type { IncomingMessage } from 'node:http';
|
2023-12-07 23:22:08 +00:00
|
|
|
import { defineConfig } from 'vite';
|
2024-10-15 19:11:55 +00:00
|
|
|
import type { PluginOption, UserConfig } from 'vite';
|
2024-01-29 12:39:34 +00:00
|
|
|
import * as yaml from 'js-yaml';
|
2023-12-24 07:16:58 +00:00
|
|
|
import locales from '../../locales/index.js';
|
2023-12-07 23:22:08 +00:00
|
|
|
import { getConfig } from './vite.config.js';
|
2024-10-16 01:42:19 +00:00
|
|
|
import packageInfo from './package.json' with { type: 'json' };
|
2023-12-07 23:22:08 +00:00
|
|
|
|
|
|
|
dns.setDefaultResultOrder('ipv4first');
|
|
|
|
|
|
|
|
const defaultConfig = getConfig();
|
|
|
|
|
2024-01-29 12:39:34 +00:00
|
|
|
const { port } = yaml.load(await readFile('../../.config/default.yml', 'utf-8'));
|
|
|
|
|
|
|
|
const httpUrl = `http://localhost:${port}/`;
|
|
|
|
const websocketUrl = `ws://localhost:${port}/`;
|
2024-09-09 11:57:36 +00:00
|
|
|
const embedUrl = `http://localhost:5174/`;
|
2024-01-29 12:39:34 +00:00
|
|
|
|
2024-07-06 02:46:43 +00:00
|
|
|
// activitypubリクエストはProxyを通し、それ以外はViteの開発サーバーを返す
|
|
|
|
function varyHandler(req: IncomingMessage) {
|
|
|
|
if (req.headers.accept?.includes('application/activity+json')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return '/index.html';
|
|
|
|
}
|
|
|
|
|
2024-10-15 19:11:55 +00:00
|
|
|
const externalPackages = [
|
|
|
|
// sharkey: Used for SkFlashPlayer, has large wasm files so it's loaded via Ruffle's preferred CDN
|
|
|
|
{
|
|
|
|
name: 'ruffle',
|
|
|
|
match: /^@ruffle-rs\/ruffle\/?(?<file>.*)$/,
|
|
|
|
path(id: string, pattern: RegExp): string {
|
|
|
|
const match = pattern.exec(id)?.groups;
|
|
|
|
return match
|
2024-10-16 17:26:33 +00:00
|
|
|
? `https://esm.sh/@ruffle-rs/ruffle@${packageInfo.dependencies['@ruffle-rs/ruffle']}/${match['file']}?raw`
|
2024-10-15 19:11:55 +00:00
|
|
|
: id;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2024-07-06 02:46:43 +00:00
|
|
|
const devConfig: UserConfig = {
|
2023-12-07 23:22:08 +00:00
|
|
|
// 基本の設定は vite.config.js から引き継ぐ
|
|
|
|
...defaultConfig,
|
|
|
|
root: 'src',
|
|
|
|
publicDir: '../assets',
|
|
|
|
base: './',
|
|
|
|
server: {
|
|
|
|
host: 'localhost',
|
|
|
|
port: 5173,
|
|
|
|
proxy: {
|
|
|
|
'/api': {
|
|
|
|
changeOrigin: true,
|
2024-01-29 12:39:34 +00:00
|
|
|
target: httpUrl,
|
2023-12-07 23:22:08 +00:00
|
|
|
},
|
2024-01-29 12:39:34 +00:00
|
|
|
'/assets': httpUrl,
|
|
|
|
'/static-assets': httpUrl,
|
|
|
|
'/client-assets': httpUrl,
|
|
|
|
'/files': httpUrl,
|
|
|
|
'/twemoji': httpUrl,
|
|
|
|
'/fluent-emoji': httpUrl,
|
2024-02-03 19:19:44 +00:00
|
|
|
'/tossface': httpUrl,
|
2024-01-29 12:39:34 +00:00
|
|
|
'/sw.js': httpUrl,
|
2023-12-07 23:22:08 +00:00
|
|
|
'/streaming': {
|
2024-01-29 12:39:34 +00:00
|
|
|
target: websocketUrl,
|
2023-12-07 23:22:08 +00:00
|
|
|
ws: true,
|
|
|
|
},
|
2024-01-29 12:39:34 +00:00
|
|
|
'/favicon.ico': httpUrl,
|
2024-09-09 11:57:36 +00:00
|
|
|
'/robots.txt': httpUrl,
|
|
|
|
'/embed.js': httpUrl,
|
|
|
|
'/embed': {
|
|
|
|
target: embedUrl,
|
|
|
|
ws: true,
|
|
|
|
},
|
2023-12-07 23:22:08 +00:00
|
|
|
'/identicon': {
|
2024-01-29 12:39:34 +00:00
|
|
|
target: httpUrl,
|
2023-12-07 23:22:08 +00:00
|
|
|
rewrite(path) {
|
|
|
|
return path.replace('@localhost:5173', '');
|
|
|
|
},
|
|
|
|
},
|
2024-01-29 12:39:34 +00:00
|
|
|
'/url': httpUrl,
|
|
|
|
'/proxy': httpUrl,
|
2024-03-05 08:27:33 +00:00
|
|
|
'/_info_card_': httpUrl,
|
|
|
|
'/bios': httpUrl,
|
|
|
|
'/cli': httpUrl,
|
2024-04-27 11:26:55 +00:00
|
|
|
'/inbox': httpUrl,
|
2024-07-25 08:03:00 +00:00
|
|
|
'/emoji/': httpUrl,
|
2024-04-27 11:26:55 +00:00
|
|
|
'/notes': {
|
|
|
|
target: httpUrl,
|
2024-07-06 02:46:43 +00:00
|
|
|
bypass: varyHandler,
|
2024-04-27 11:26:55 +00:00
|
|
|
},
|
|
|
|
'/users': {
|
|
|
|
target: httpUrl,
|
2024-07-06 02:46:43 +00:00
|
|
|
bypass: varyHandler,
|
2024-04-27 11:26:55 +00:00
|
|
|
},
|
|
|
|
'/.well-known': {
|
|
|
|
target: httpUrl,
|
|
|
|
},
|
2023-12-07 23:22:08 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
build: {
|
|
|
|
...defaultConfig.build,
|
|
|
|
rollupOptions: {
|
|
|
|
...defaultConfig.build?.rollupOptions,
|
2024-10-15 19:11:55 +00:00
|
|
|
external: externalPackages.map(p => p.match),
|
|
|
|
output: {
|
|
|
|
...defaultConfig.build?.rollupOptions?.output,
|
|
|
|
paths(id) {
|
|
|
|
for (const p of externalPackages) {
|
|
|
|
if (p.match.test(id)) {
|
|
|
|
return p.path(id, p.match);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
},
|
|
|
|
},
|
2023-12-07 23:22:08 +00:00
|
|
|
input: 'index.html',
|
|
|
|
},
|
|
|
|
},
|
2023-12-14 11:16:02 +00:00
|
|
|
|
|
|
|
define: {
|
|
|
|
...defaultConfig.define,
|
|
|
|
_LANGS_FULL_: JSON.stringify(Object.entries(locales)),
|
|
|
|
},
|
2023-12-07 23:22:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default defineConfig(({ command, mode }) => devConfig);
|
|
|
|
|