2023-01-14 03:10:41 +01:00
|
|
|
|
import path from 'path';
|
2023-04-13 16:23:11 +02:00
|
|
|
|
import pluginReplace from '@rollup/plugin-replace';
|
2022-05-01 15:51:07 +02:00
|
|
|
|
import pluginVue from '@vitejs/plugin-vue';
|
2023-04-04 02:38:34 +02:00
|
|
|
|
import { type UserConfig, defineConfig } from 'vite';
|
2022-05-01 15:51:07 +02:00
|
|
|
|
|
2023-12-24 08:16:58 +01:00
|
|
|
|
import locales from '../../locales/index.js';
|
2022-05-01 15:51:07 +02:00
|
|
|
|
import meta from '../../package.json';
|
2024-03-20 02:30:45 +01:00
|
|
|
|
import packageInfo from './package.json' assert { type: 'json' };
|
2023-12-24 08:16:58 +01:00
|
|
|
|
import pluginUnwindCssModuleClassName from './lib/rollup-plugin-unwind-css-module-class-name.js';
|
|
|
|
|
import pluginJson5 from './vite.json5.js';
|
2022-05-01 15:51:07 +02:00
|
|
|
|
|
2024-03-14 12:41:24 +01:00
|
|
|
|
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue', '.wasm'];
|
2022-05-01 15:51:07 +02:00
|
|
|
|
|
2024-03-20 02:30:45 +01:00
|
|
|
|
/**
|
|
|
|
|
* Misskeyのフロントエンドにバンドルせず、CDNなどから別途読み込むリソースを記述する。
|
|
|
|
|
* CDNを使わずにバンドルしたい場合、以下の配列から該当要素を削除orコメントアウトすればOK
|
|
|
|
|
*/
|
|
|
|
|
const externalPackages = [
|
|
|
|
|
// shiki(コードブロックのシンタックスハイライトで使用中)はテーマ・言語の定義の容量が大きいため、それらはCDNから読み込む
|
|
|
|
|
{
|
|
|
|
|
name: 'shiki',
|
|
|
|
|
match: /^shiki\/(?<subPkg>(langs|themes))$/,
|
|
|
|
|
path(id: string, pattern: RegExp): string {
|
|
|
|
|
const match = pattern.exec(id)?.groups;
|
|
|
|
|
return match
|
|
|
|
|
? `https://esm.sh/shiki@${packageInfo.dependencies.shiki}/${match['subPkg']}`
|
|
|
|
|
: id;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2023-01-10 00:39:19 +01:00
|
|
|
|
const hash = (str: string, seed = 0): number => {
|
|
|
|
|
let h1 = 0xdeadbeef ^ seed,
|
|
|
|
|
h2 = 0x41c6ce57 ^ seed;
|
|
|
|
|
for (let i = 0, ch; i < str.length; i++) {
|
|
|
|
|
ch = str.charCodeAt(i);
|
|
|
|
|
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
|
|
|
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
|
|
|
}
|
2023-03-09 04:48:39 +01:00
|
|
|
|
|
2023-01-10 00:39:19 +01:00
|
|
|
|
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
|
|
|
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
2023-03-09 04:48:39 +01:00
|
|
|
|
|
2023-01-10 00:39:19 +01:00
|
|
|
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const BASE62_DIGITS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
2023-12-24 08:16:58 +01:00
|
|
|
|
|
2023-01-10 00:39:19 +01:00
|
|
|
|
function toBase62(n: number): string {
|
|
|
|
|
if (n === 0) {
|
|
|
|
|
return '0';
|
|
|
|
|
}
|
2023-03-09 04:48:39 +01:00
|
|
|
|
let result = '';
|
2023-01-10 00:39:19 +01:00
|
|
|
|
while (n > 0) {
|
|
|
|
|
result = BASE62_DIGITS[n % BASE62_DIGITS.length] + result;
|
|
|
|
|
n = Math.floor(n / BASE62_DIGITS.length);
|
|
|
|
|
}
|
2023-03-09 04:48:39 +01:00
|
|
|
|
|
2023-01-10 00:39:19 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-04 02:38:34 +02:00
|
|
|
|
export function getConfig(): UserConfig {
|
2022-05-01 15:51:07 +02:00
|
|
|
|
return {
|
2022-12-20 05:05:36 +01:00
|
|
|
|
base: '/vite/',
|
2022-05-01 15:51:07 +02:00
|
|
|
|
|
2023-05-06 03:25:15 +02:00
|
|
|
|
server: {
|
|
|
|
|
port: 5173,
|
|
|
|
|
},
|
|
|
|
|
|
2022-05-01 15:51:07 +02:00
|
|
|
|
plugins: [
|
2023-12-07 06:42:09 +01:00
|
|
|
|
pluginVue(),
|
2023-06-01 10:19:46 +02:00
|
|
|
|
pluginUnwindCssModuleClassName(),
|
2022-05-01 15:51:07 +02:00
|
|
|
|
pluginJson5(),
|
2024-06-21 13:24:04 +02:00
|
|
|
|
pluginReplace({
|
|
|
|
|
preventAssignment: true,
|
|
|
|
|
values: {
|
|
|
|
|
'ti ti-terminal-2': 'ph-terminal-window ph-bold ph-lg',
|
2024-06-21 13:32:48 +02:00
|
|
|
|
'ti ti-download': 'ph-download ph-bold ph-lg',
|
2024-06-21 13:38:50 +02:00
|
|
|
|
'ti ti-circle-x': 'ph-x-circle ph-bold ph-lg',
|
2024-06-21 13:42:33 +02:00
|
|
|
|
'ti ti-plus': 'ph-plus ph-bold ph-lg',
|
2024-06-21 13:49:30 +02:00
|
|
|
|
'ti ti-planet': 'ph-planet ph-bold ph-lg',
|
|
|
|
|
'ti ti-world-x': 'ph-planet ph-bold ph-lg',
|
|
|
|
|
'ti ti-world-search': 'ph-planet ph-bold ph-lg',
|
2024-06-21 13:57:35 +02:00
|
|
|
|
'ti ti-chevron-right': 'ph-caret-right ph-bold ph-lg',
|
|
|
|
|
'ti ti-chevrons-right': 'ph-caret-right ph-bold ph-lg',
|
|
|
|
|
'ti ti-chevron-right ti-fw': 'ph-caret-right ph-bold ph-lg',
|
2024-06-21 14:04:54 +02:00
|
|
|
|
'ti ti-dots': 'ph-dots-three ph-bold ph-lg',
|
2024-06-21 14:09:24 +02:00
|
|
|
|
'ti ti-check': 'ph-check ph-bold ph-lg',
|
2024-06-21 14:13:02 +02:00
|
|
|
|
'ti ti-device-floppy': 'ph-floppy-disk ph-bold ph-lg',
|
2024-06-21 14:20:42 +02:00
|
|
|
|
'ti ti-shield': 'ph-shield ph-bold ph-lg',
|
|
|
|
|
'ti ti-shield-lock': 'ph-shield ph-bold ph-lg',
|
2024-06-21 14:23:23 +02:00
|
|
|
|
'ti ti-confetti': 'ph-confetti ph-bold ph-lg',
|
2024-06-21 14:28:16 +02:00
|
|
|
|
'ti ti-home': 'ph-house ph-bold ph-lg',
|
2024-06-21 14:30:42 +02:00
|
|
|
|
'ti ti-clock': 'ph-clock ph-bold ph-lg',
|
2024-06-21 14:44:45 +02:00
|
|
|
|
'ti ti-pencil': 'ph-pencil-simple ph-bold ph-lg',
|
|
|
|
|
'ti ti-pencil ti-fw': 'ph-pencil-simple ph-bold ph-lg',
|
2024-06-21 13:24:04 +02:00
|
|
|
|
},
|
|
|
|
|
}),
|
2023-04-13 16:23:11 +02:00
|
|
|
|
...process.env.NODE_ENV === 'production'
|
|
|
|
|
? [
|
|
|
|
|
pluginReplace({
|
|
|
|
|
preventAssignment: true,
|
|
|
|
|
values: {
|
|
|
|
|
'isChromatic()': JSON.stringify(false),
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
]
|
|
|
|
|
: [],
|
2022-05-01 15:51:07 +02:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
|
extensions,
|
|
|
|
|
alias: {
|
|
|
|
|
'@/': __dirname + '/src/',
|
|
|
|
|
'/client-assets/': __dirname + '/assets/',
|
|
|
|
|
'/static-assets/': __dirname + '/../backend/assets/',
|
2023-01-22 13:25:55 +01:00
|
|
|
|
'/fluent-emojis/': __dirname + '/../../fluent-emojis/dist/',
|
2024-01-04 20:42:25 +01:00
|
|
|
|
'/tossface/': __dirname + '/../../tossface-emojis/dist/',
|
2023-01-22 13:25:55 +01:00
|
|
|
|
'/fluent-emoji/': __dirname + '/../../fluent-emojis/dist/',
|
2022-05-01 15:51:07 +02:00
|
|
|
|
},
|
2023-01-10 00:39:19 +01:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
css: {
|
|
|
|
|
modules: {
|
2023-04-04 02:38:34 +02:00
|
|
|
|
generateScopedName(name, filename, _css): string {
|
2023-01-16 05:59:14 +01:00
|
|
|
|
const id = (path.relative(__dirname, filename.split('?')[0]) + '-' + name).replace(/[\\\/\.\?&=]/g, '-').replace(/(src-|vue-)/g, '');
|
2023-10-18 00:41:41 +02:00
|
|
|
|
const shortId = id.replace(/^(components(-global)?|widgets|ui(-_common_)?)-/, '');
|
|
|
|
|
return shortId + '-' + toBase62(hash(id)).substring(0, 4);
|
2023-01-10 00:39:19 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2022-05-01 15:51:07 +02:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
define: {
|
|
|
|
|
_VERSION_: JSON.stringify(meta.version),
|
|
|
|
|
_LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v._lang_])),
|
|
|
|
|
_ENV_: JSON.stringify(process.env.NODE_ENV),
|
|
|
|
|
_DEV_: process.env.NODE_ENV !== 'production',
|
|
|
|
|
_PERF_PREFIX_: JSON.stringify('Misskey:'),
|
|
|
|
|
_DATA_TRANSFER_DRIVE_FILE_: JSON.stringify('mk_drive_file'),
|
|
|
|
|
_DATA_TRANSFER_DRIVE_FOLDER_: JSON.stringify('mk_drive_folder'),
|
|
|
|
|
_DATA_TRANSFER_DECK_COLUMN_: JSON.stringify('mk_deck_column'),
|
2023-05-14 06:23:25 +02:00
|
|
|
|
__VUE_OPTIONS_API__: true,
|
2022-05-01 15:51:07 +02:00
|
|
|
|
__VUE_PROD_DEVTOOLS__: false,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
build: {
|
2023-01-09 08:16:00 +01:00
|
|
|
|
target: [
|
2023-09-15 12:49:52 +02:00
|
|
|
|
'chrome116',
|
|
|
|
|
'firefox116',
|
2023-01-09 08:45:18 +01:00
|
|
|
|
'safari16',
|
2023-01-09 08:16:00 +01:00
|
|
|
|
],
|
2022-05-01 15:51:07 +02:00
|
|
|
|
manifest: 'manifest.json',
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
input: {
|
2023-05-15 12:08:46 +02:00
|
|
|
|
app: './src/_boot_.ts',
|
2022-05-01 15:51:07 +02:00
|
|
|
|
},
|
2024-03-20 02:30:45 +01:00
|
|
|
|
external: externalPackages.map(p => p.match),
|
2022-05-01 15:51:07 +02:00
|
|
|
|
output: {
|
|
|
|
|
manualChunks: {
|
2022-06-20 10:38:49 +02:00
|
|
|
|
vue: ['vue'],
|
2023-01-17 09:36:18 +01:00
|
|
|
|
photoswipe: ['photoswipe', 'photoswipe/lightbox', 'photoswipe/style.css'],
|
2022-05-01 15:51:07 +02:00
|
|
|
|
},
|
2023-05-30 11:55:22 +02:00
|
|
|
|
chunkFileNames: process.env.NODE_ENV === 'production' ? '[hash:8].js' : '[name]-[hash:8].js',
|
|
|
|
|
assetFileNames: process.env.NODE_ENV === 'production' ? '[hash:8][extname]' : '[name]-[hash:8][extname]',
|
2024-03-20 02:30:45 +01:00
|
|
|
|
paths(id) {
|
|
|
|
|
for (const p of externalPackages) {
|
|
|
|
|
if (p.match.test(id)) {
|
|
|
|
|
return p.path(id, p.match);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
},
|
2022-05-01 15:51:07 +02:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
cssCodeSplit: true,
|
2022-12-20 05:05:36 +01:00
|
|
|
|
outDir: __dirname + '/../../built/_vite_',
|
2022-05-01 15:51:07 +02:00
|
|
|
|
assetsDir: '.',
|
|
|
|
|
emptyOutDir: false,
|
2022-12-20 05:05:36 +01:00
|
|
|
|
sourcemap: process.env.NODE_ENV === 'development',
|
2022-05-01 15:51:07 +02:00
|
|
|
|
reportCompressedSize: false,
|
2023-03-30 02:33:19 +02:00
|
|
|
|
|
|
|
|
|
// https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies
|
|
|
|
|
commonjsOptions: {
|
2024-01-20 01:53:26 +01:00
|
|
|
|
include: [/misskey-js/, /misskey-reversi/, /misskey-bubble-game/, /node_modules/],
|
2023-03-30 02:33:19 +02:00
|
|
|
|
},
|
2022-05-01 15:51:07 +02:00
|
|
|
|
},
|
2023-03-09 04:48:39 +01:00
|
|
|
|
|
2023-05-19 02:44:06 +02:00
|
|
|
|
worker: {
|
|
|
|
|
format: 'es',
|
|
|
|
|
},
|
|
|
|
|
|
2023-03-09 04:48:39 +01:00
|
|
|
|
test: {
|
|
|
|
|
environment: 'happy-dom',
|
|
|
|
|
deps: {
|
2023-11-29 02:41:11 +01:00
|
|
|
|
optimizer: {
|
|
|
|
|
web: {
|
|
|
|
|
include: [
|
|
|
|
|
// XXX: misskey-dev/browser-image-resizer has no "type": "module"
|
|
|
|
|
'browser-image-resizer',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-03-09 04:48:39 +01:00
|
|
|
|
},
|
2024-01-20 00:11:59 +01:00
|
|
|
|
includeSource: ['src/**/*.ts'],
|
2023-03-09 04:48:39 +01:00
|
|
|
|
},
|
2022-06-20 10:38:49 +02:00
|
|
|
|
};
|
2023-04-04 02:38:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const config = defineConfig(({ command, mode }) => getConfig());
|
|
|
|
|
|
|
|
|
|
export default config;
|