mirror of
https://github.com/OpenListTeam/OpenList-Frontend.git
synced 2026-09-20 17:11:46 +00:00
118 lines
3.6 KiB
TypeScript
118 lines
3.6 KiB
TypeScript
import path from "path"
|
|
import { defineConfig } from "vite"
|
|
import solidPlugin from "vite-plugin-solid"
|
|
import legacy from "@vitejs/plugin-legacy"
|
|
import { dynamicBase } from "vite-plugin-dynamic-base"
|
|
import { viteStaticCopy } from "vite-plugin-static-copy"
|
|
import type { Plugin } from "vite"
|
|
|
|
// vite-plugin-dynamic-base converts data-src → src in its generateBundle hook,
|
|
// but @vitejs/plugin-legacy expects data-src on vite-legacy-polyfill so the
|
|
// legacy detection script can read it. This plugin runs its generateBundle
|
|
// after dynamicBase (enforce:post, registered last) and restores data-src.
|
|
function fixLegacyPolyfillDataSrc(): Plugin {
|
|
return {
|
|
name: "fix-legacy-polyfill-data-src",
|
|
enforce: "post",
|
|
apply: "build",
|
|
generateBundle(_, bundle) {
|
|
for (const chunk of Object.values(bundle)) {
|
|
if (
|
|
chunk.type === "asset" &&
|
|
chunk.fileName.endsWith(".html") &&
|
|
typeof chunk.source === "string"
|
|
) {
|
|
chunk.source = chunk.source.replace(
|
|
/("id"\s*:\s*"vite-legacy-polyfill"[^}]*?)"src"\s*:/,
|
|
(match) => match.replace(/"src"\s*:/, '"data-src":'),
|
|
)
|
|
}
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
resolve: {
|
|
alias: {
|
|
"~": path.resolve(__dirname, "src"),
|
|
// "@solidjs/router": path.resolve(__dirname, "solid-router/src"),
|
|
"solid-icons": path.resolve(__dirname, "node_modules/solid-icons"),
|
|
},
|
|
},
|
|
plugins: [
|
|
solidPlugin(),
|
|
legacy({
|
|
targets: ["defaults"],
|
|
}),
|
|
dynamicBase({
|
|
// dynamic public path var string, default window.__dynamic_base__
|
|
publicPath: "window.__dynamic_base__",
|
|
// dynamic load resources on index.html, default false. maybe change default true
|
|
transformIndexHtml: true,
|
|
transformIndexHtmlConfig: {
|
|
insertBodyAfter: true,
|
|
},
|
|
}),
|
|
process.env.VITE_LITE !== "true"
|
|
? viteStaticCopy({
|
|
targets: [
|
|
{
|
|
src: "node_modules/monaco-editor/min/*",
|
|
dest: "static/monaco-editor",
|
|
},
|
|
{
|
|
src: "node_modules/katex/dist/katex.min.css",
|
|
dest: "static/katex",
|
|
},
|
|
{
|
|
src: "node_modules/katex/dist/fonts/*",
|
|
dest: "static/katex/fonts",
|
|
},
|
|
{
|
|
src: "node_modules/mermaid/dist/mermaid.min.js",
|
|
dest: "static/mermaid",
|
|
},
|
|
{
|
|
src: "node_modules/libheif-js/libheif-wasm/libheif.{js,wasm}",
|
|
dest: "static/libheif",
|
|
},
|
|
{
|
|
src: "node_modules/@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.{js,wasm}",
|
|
dest: "static/libass-wasm",
|
|
},
|
|
{
|
|
src: "src/components/artplayer-plugin-ass/fonts/*",
|
|
dest: "static/fonts",
|
|
},
|
|
],
|
|
})
|
|
: null,
|
|
fixLegacyPolyfillDataSrc(),
|
|
],
|
|
base: process.env.NODE_ENV === "production" ? "/__dynamic_base__/" : "/",
|
|
// base: "/",
|
|
build: {
|
|
// target: "es2015", //next
|
|
// polyfillDynamicImport: false,
|
|
},
|
|
// experimental: {
|
|
// renderBuiltUrl: (filename, { type, hostId, hostType }) => {
|
|
// if (type === "asset") {
|
|
// return { runtime: `window.OPENLIST_CONFIG.cdn/${filename}` };
|
|
// }
|
|
// return { relative: true };
|
|
// },
|
|
// },
|
|
server: {
|
|
host: "0.0.0.0",
|
|
proxy: {
|
|
"/api": {
|
|
target: "http://localhost:5244",
|
|
changeOrigin: true,
|
|
// rewrite: (path) => path.replace(/^\/api/, ""),
|
|
},
|
|
},
|
|
},
|
|
})
|