2023-01-14 02:10:41 +00:00
|
|
|
import path from 'path';
|
2022-05-01 13:51:07 +00:00
|
|
|
import pluginVue from '@vitejs/plugin-vue';
|
|
|
|
import { defineConfig } from 'vite';
|
2023-03-09 03:48:39 +00:00
|
|
|
import { configDefaults as vitestConfigDefaults } from 'vitest/config';
|
2022-05-01 13:51:07 +00:00
|
|
|
|
|
|
|
import locales from '../../locales';
|
|
|
|
import meta from '../../package.json';
|
2022-06-20 08:38:49 +00:00
|
|
|
import pluginJson5 from './vite.json5';
|
2022-05-01 13:51:07 +00:00
|
|
|
|
|
|
|
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue'];
|
|
|
|
|
2023-01-09 23:39:19 +00: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 03:48:39 +00:00
|
|
|
|
2023-01-09 23:39:19 +00: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 03:48:39 +00:00
|
|
|
|
2023-01-09 23:39:19 +00:00
|
|
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
const BASE62_DIGITS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
function toBase62(n: number): string {
|
|
|
|
if (n === 0) {
|
|
|
|
return '0';
|
|
|
|
}
|
2023-03-09 03:48:39 +00:00
|
|
|
let result = '';
|
2023-01-09 23:39:19 +00:00
|
|
|
while (n > 0) {
|
|
|
|
result = BASE62_DIGITS[n % BASE62_DIGITS.length] + result;
|
|
|
|
n = Math.floor(n / BASE62_DIGITS.length);
|
|
|
|
}
|
2023-03-09 03:48:39 +00:00
|
|
|
|
2023-01-09 23:39:19 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-05-01 13:51:07 +00:00
|
|
|
export default defineConfig(({ command, mode }) => {
|
|
|
|
return {
|
2022-12-20 04:05:36 +00:00
|
|
|
base: '/vite/',
|
2022-05-01 13:51:07 +00:00
|
|
|
|
|
|
|
plugins: [
|
|
|
|
pluginVue({
|
|
|
|
reactivityTransform: true,
|
|
|
|
}),
|
|
|
|
pluginJson5(),
|
|
|
|
],
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions,
|
|
|
|
alias: {
|
|
|
|
'@/': __dirname + '/src/',
|
|
|
|
'/client-assets/': __dirname + '/assets/',
|
|
|
|
'/static-assets/': __dirname + '/../backend/assets/',
|
2023-01-22 12:25:55 +00:00
|
|
|
'/fluent-emojis/': __dirname + '/../../fluent-emojis/dist/',
|
|
|
|
'/fluent-emoji/': __dirname + '/../../fluent-emojis/dist/',
|
2022-05-01 13:51:07 +00:00
|
|
|
},
|
2023-01-09 23:39:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
css: {
|
|
|
|
modules: {
|
|
|
|
generateScopedName: (name, filename, css) => {
|
2023-01-16 04:59:14 +00:00
|
|
|
const id = (path.relative(__dirname, filename.split('?')[0]) + '-' + name).replace(/[\\\/\.\?&=]/g, '-').replace(/(src-|vue-)/g, '');
|
2023-01-10 02:15:29 +00:00
|
|
|
if (process.env.NODE_ENV === 'production') {
|
2023-01-16 04:59:14 +00:00
|
|
|
return 'x' + toBase62(hash(id)).substring(0, 4);
|
2023-01-10 02:15:29 +00:00
|
|
|
} else {
|
2023-01-16 04:59:14 +00:00
|
|
|
return id;
|
2023-01-10 02:15:29 +00:00
|
|
|
}
|
2023-01-09 23:39:19 +00:00
|
|
|
},
|
|
|
|
},
|
2022-05-01 13:51:07 +00: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'),
|
|
|
|
__VUE_OPTIONS_API__: true,
|
|
|
|
__VUE_PROD_DEVTOOLS__: false,
|
|
|
|
},
|
|
|
|
|
2023-03-16 21:13:42 +00:00
|
|
|
// https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies
|
|
|
|
optimizeDeps: {
|
|
|
|
include: ['misskey-js'],
|
|
|
|
},
|
|
|
|
|
2022-05-01 13:51:07 +00:00
|
|
|
build: {
|
2023-01-09 07:16:00 +00:00
|
|
|
target: [
|
2023-01-09 07:45:18 +00:00
|
|
|
'chrome108',
|
|
|
|
'firefox109',
|
|
|
|
'safari16',
|
2023-01-09 07:16:00 +00:00
|
|
|
],
|
2022-05-01 13:51:07 +00:00
|
|
|
manifest: 'manifest.json',
|
|
|
|
rollupOptions: {
|
|
|
|
input: {
|
|
|
|
app: './src/init.ts',
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
manualChunks: {
|
2022-06-20 08:38:49 +00:00
|
|
|
vue: ['vue'],
|
2023-01-17 08:36:18 +00:00
|
|
|
photoswipe: ['photoswipe', 'photoswipe/lightbox', 'photoswipe/style.css'],
|
2022-05-01 13:51:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cssCodeSplit: true,
|
2022-12-20 04:05:36 +00:00
|
|
|
outDir: __dirname + '/../../built/_vite_',
|
2022-05-01 13:51:07 +00:00
|
|
|
assetsDir: '.',
|
|
|
|
emptyOutDir: false,
|
2022-12-20 04:05:36 +00:00
|
|
|
sourcemap: process.env.NODE_ENV === 'development',
|
2022-05-01 13:51:07 +00:00
|
|
|
reportCompressedSize: false,
|
2023-03-16 21:13:42 +00:00
|
|
|
|
|
|
|
// https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies
|
|
|
|
commonjsOptions: {
|
|
|
|
include: [/misskey-js/, /node_modules/],
|
|
|
|
},
|
2022-05-01 13:51:07 +00:00
|
|
|
},
|
2023-03-09 03:48:39 +00:00
|
|
|
|
|
|
|
test: {
|
|
|
|
environment: 'happy-dom',
|
|
|
|
deps: {
|
|
|
|
inline: [
|
|
|
|
// XXX: misskey-dev/browser-image-resizer has no "type": "module"
|
|
|
|
'browser-image-resizer',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2022-06-20 08:38:49 +00:00
|
|
|
};
|
2022-05-01 13:51:07 +00:00
|
|
|
});
|