bigbuffet-rw/packages/pl-fe/vite.config.ts

188 lines
4.7 KiB
TypeScript
Raw Normal View History

/// <reference types="vitest" />
2023-09-18 17:14:23 -07:00
import fs from 'node:fs';
import { fileURLToPath, URL } from 'node:url';
2023-09-13 10:04:17 -07:00
import react from '@vitejs/plugin-react';
import { bundleStats } from 'rollup-plugin-bundle-stats';
2023-09-13 10:04:17 -07:00
import { defineConfig } from 'vite';
2023-09-20 16:50:17 -07:00
import checker from 'vite-plugin-checker';
2023-09-13 10:04:17 -07:00
import compileTime from 'vite-plugin-compile-time';
import { createHtmlPlugin } from 'vite-plugin-html';
2023-09-15 12:37:09 -07:00
import { VitePWA } from 'vite-plugin-pwa';
2023-09-13 10:04:17 -07:00
import vitePluginRequire from 'vite-plugin-require';
import { viteStaticCopy } from 'vite-plugin-static-copy';
const config = defineConfig(({ command }) => ({
2023-09-13 10:04:17 -07:00
build: {
assetsDir: 'packs',
assetsInlineLimit: 0,
2023-09-14 17:14:16 -07:00
rollupOptions: {
output: {
assetFileNames: 'packs/assets/[name]-[hash].[ext]',
chunkFileNames: 'packs/js/[name]-[hash].js',
entryFileNames: 'packs/[name]-[hash].js',
},
},
2023-10-07 09:50:42 -07:00
sourcemap: true,
2023-09-13 10:04:17 -07:00
},
2023-09-18 14:57:13 -07:00
assetsInclude: ['**/*.oga'],
2023-09-13 10:24:49 -07:00
server: {
2024-02-11 14:39:45 -08:00
port: Number(process.env.PORT ?? 3036),
2023-09-13 10:24:49 -07:00
},
2023-09-13 10:04:17 -07:00
plugins: [
2023-09-20 16:50:17 -07:00
checker({ typescript: true }),
2023-09-13 10:04:17 -07:00
// @ts-ignore
vitePluginRequire.default(),
2023-09-15 12:37:09 -07:00
compileTime(),
2023-09-13 10:04:17 -07:00
createHtmlPlugin({
2023-09-18 15:39:22 -07:00
template: 'index.html',
minify: {
collapseWhitespace: true,
removeComments: false,
},
2023-09-18 17:14:23 -07:00
inject: {
data: {
snippets: readFileContents('custom/snippets.html'),
},
},
2023-09-13 10:04:17 -07:00
}),
react(),
2023-09-15 12:37:09 -07:00
VitePWA({
injectRegister: null,
strategies: 'injectManifest',
injectManifest: {
injectionPoint: undefined,
plugins: [
// @ts-ignore
compileTime(),
],
},
manifestFilename: 'manifest.json',
manifest: {
name: 'pl-fe',
short_name: 'pl-fe',
description: 'Web-based federated social media client, a fork of Soapbox',
icons: [
{
src: '/instance/images/logo.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any',
},
],
display: 'standalone',
display_override: [
'window-controls-overlay',
],
theme_color: '#d80482',
categories: ['social'],
share_target: {
params: {
title: 'title',
text: 'text',
url: 'url',
},
action: 'share',
method: 'GET',
},
shortcuts: [
{
name: 'Search',
url: '/search',
icons: [
{
src: '/instance/images/shortcuts/search.png',
sizes: '192x192',
type: 'image/png',
},
],
},
{
name: 'Notifications',
url: '/notifications',
icons: [
{
src: '/instance/images/shortcuts/notifications.png',
sizes: '192x192',
type: 'image/png',
},
],
},
{
name: 'Chats',
url: '/chats',
icons: [
{
src: '/instance/images/shortcuts/chats.png',
sizes: '192x192',
type: 'image/png',
},
],
},
],
start_url: '/',
id: '/',
2023-09-15 12:37:09 -07:00
},
2023-09-18 14:57:13 -07:00
srcDir: 'src/service-worker',
2023-09-15 12:37:09 -07:00
filename: 'sw.ts',
}),
2023-09-13 10:04:17 -07:00
viteStaticCopy({
targets: [{
src: './node_modules/@twemoji/svg/*',
2023-09-13 10:04:17 -07:00
dest: 'packs/emoji/',
}, {
src: './favicon.ico',
dest: '.',
2023-09-18 14:59:17 -07:00
}, {
src: './src/instance',
dest: '.',
2023-09-18 17:20:08 -07:00
}, {
src: './custom/instance',
dest: '.',
}, {
src: './node_modules/fasttext.wasm.js/dist/models/language-identification/assets/lid.176.ftz',
dest: 'fastText/models/',
}, {
src: './node_modules/fasttext.wasm.js/dist/core/fastText.common.wasm',
dest: 'fastText/',
2023-09-13 10:04:17 -07:00
}],
}),
bundleStats(),
2024-01-12 15:25:15 -08:00
{
name: 'mock-api',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (/^\/api\//.test(req.url!)) {
res.statusCode = 404;
res.end('Not Found');
} else {
next();
}
});
},
},
2023-09-13 10:04:17 -07:00
],
resolve: {
alias: [
{ find: 'pl-fe', replacement: fileURLToPath(new URL('./src', import.meta.url)) },
2023-09-13 10:04:17 -07:00
],
dedupe: ['@floating-ui/react', 'tabbable', 'query-string', 'valibot'],
2023-09-13 10:04:17 -07:00
},
test: {
globals: true,
environment: 'jsdom',
2023-09-18 14:57:13 -07:00
setupFiles: 'src/jest/test-setup.ts',
},
}));
2023-09-18 17:14:23 -07:00
/** Return file as string, or return empty string if the file isn't found. */
const readFileContents = (path: string) => {
2023-09-18 17:14:23 -07:00
try {
return fs.readFileSync(path, 'utf8');
} catch {
return '';
}
};
export { config as default };