mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-26 04:02:47 +00:00
99 lines
2.6 KiB
TypeScript
99 lines
2.6 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
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: (id) => {
|
|
if (id.includes("monaco-editor")) {
|
|
return `monaco`;
|
|
}
|
|
if (id.includes("@codemirror")) {
|
|
return "codemirror";
|
|
}
|
|
if (
|
|
id.toLocaleLowerCase().includes("excalidraw") ||
|
|
id.includes("browser-fs-access") ||
|
|
id.includes("image-blob-reduce") ||
|
|
id.includes("pica")
|
|
) {
|
|
return "excalidraw";
|
|
}
|
|
if (id.includes("mermaid") || id.includes("katex")) {
|
|
return "mermaid";
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
host: "0.0.0.0",
|
|
cors: false,
|
|
proxy: {
|
|
"/api": { target: backend },
|
|
"/s/": { target: backend },
|
|
"/f/": { target: backend },
|
|
"/manifest.json": { target: backend },
|
|
},
|
|
},
|
|
});
|