frontend/vite.config.ts
Darren Yu 8bba067340
feat(ui): change loader to mui-like style, and async load js and css (#250)
* fix (ui): async load js and css

currently, loader only appears when js and css load failed. this fix to show loading animation while js and css is loading.

* feat(ui): change loader to mui-like style
2025-04-24 15:04:00 +08:00

81 lines
2.1 KiB
TypeScript

import react from "@vitejs/plugin-react-swc";
import { promises as fs } from "fs";
import { resolve } from "path";
import { defineConfig } from "vite";
// import mkcert from "vite-plugin-mkcert";
import { VitePWA } from "vite-plugin-pwa";
import { viteStaticCopy } from "vite-plugin-static-copy";
const backend = "http://localhost:5212";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
VitePWA({
registerType: "prompt",
injectRegister: "auto",
manifest: false,
workbox: {
maximumFileSizeToCacheInBytes: 10000000,
navigateFallbackDenylist: [
/^\/pdfviewer.html/,
/^\/api\/(.+)/,
/^\/f\/(.+)/,
/^\/s\/(.+)/,
],
},
devOptions: {
enabled: true,
},
}),
viteStaticCopy({
targets: [
{
src: "node_modules/pdfjs-dist/build/*.mjs",
dest: "assets/pdfjs",
},
],
}),
{
name: "load-stylesheet-async",
transformIndexHtml(html) {
return html.replace(
/<link rel="stylesheet" crossorigin href="(.+?)">/g,
`<link rel="stylesheet" crossorigin href="$1" media="print" onload="this.media='all'">`
);
},
},
{
name: "generate-version",
async writeBundle(outputOptions) {
const version = {
name: process.env.npm_package_name,
version: process.env.npm_package_version,
};
const path = resolve(__dirname, outputOptions.dir, "version.json");
await fs.writeFile(path, JSON.stringify(version));
},
},
// mkcert({
// hosts: ["devv5.cloudreve.org"],
// }),
],
define: {
__ASSETS_VERSION__: JSON.stringify(process.env.npm_package_version),
},
build: {
outDir: "build", // keep same as v3 with minimal changes
},
server: {
host: "0.0.0.0",
cors: false,
proxy: {
"/api": { target: backend },
"/s/": { target: backend },
"/f/": { target: backend },
"/manifest.json": { target: backend },
},
},
});