Files
suwayomi-material-you-webui/vite.config.ts

93 lines
3.0 KiB
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
2024-04-17 20:01:17 +02:00
/* eslint-disable import/no-extraneous-dependencies */
import path from 'path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import viteTsconfigPaths from 'vite-tsconfig-paths';
2024-03-26 23:39:25 +01:00
import legacy from '@vitejs/plugin-legacy';
2025-06-22 23:12:54 +02:00
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { VitePWA } from 'vite-plugin-pwa';
2025-08-02 23:13:50 +02:00
import 'dotenv/config';
// eslint-disable-next-line import/no-default-export
export default defineConfig(({ command }) => ({
base: command === 'serve' ? process.env.VITE_SUBPATH || './' : './',
build: {
outDir: 'build',
},
server: {
2025-08-02 23:13:50 +02:00
port: Number(process.env.PORT),
2025-08-13 00:57:46 +02:00
allowedHosts: process.env.ALLOWED_HOSTS.split(',').map((s) => s.trim()),
},
resolve: {
alias: {
2024-12-24 03:32:55 +01:00
'@': path.resolve(import.meta.dirname, './src'),
},
},
optimizeDeps: {
include: ['@mui/material/Tooltip'],
},
2024-03-26 23:39:25 +01:00
plugins: [
react(),
viteTsconfigPaths(),
legacy({
modernPolyfills: [
'es/array/to-spliced',
'es/array/to-sorted',
'es/array/find-last',
'es/array/find-last-index',
'es/object/group-by',
2024-03-26 23:39:25 +01:00
],
}),
2025-06-22 23:12:54 +02:00
nodePolyfills({
include: ['assert'],
}),
// Only setup image runtime caching
VitePWA({
registerType: 'autoUpdate',
manifest: false, // Use existing manifest
devOptions: {
enabled: true,
},
workbox: {
globPatterns: [],
runtimeCaching: [
{
urlPattern: ({ request, url }) => {
if (request.destination === 'image') {
return true;
}
const { pathname } = url;
return (
pathname.match(/\/chapter\/[0-9]+\/page\/[0-9]+/g) ||
pathname.match(/\/manga\/[0-9]+\/thumbnail/g) ||
pathname.includes('/extension/icon/')
);
},
handler: 'CacheFirst',
options: {
cacheName: 'image-cache',
expiration: {
maxEntries: 10000,
purgeOnQuotaError: true,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
},
}),
2024-03-26 23:39:25 +01:00
],
}));