mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-25 19:52:48 +00:00
* 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
81 lines
2.1 KiB
TypeScript
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 },
|
|
},
|
|
},
|
|
});
|