104 lines
3.0 KiB
TypeScript
104 lines
3.0 KiB
TypeScript
import { defineConfig } from "vitepress";
|
|
import { execSync } from "node:child_process";
|
|
|
|
const host = process.env.TAURI_DEV_HOST;
|
|
|
|
const {
|
|
IMG_ORIGIN = `https://git.polv.cc/polv/yt2press/raw/branch/${
|
|
execSync("git branch --show-current").toString().trimEnd()
|
|
}/docs/public`,
|
|
} = process.env;
|
|
|
|
// https://vitepress.dev/reference/site-config
|
|
export default defineConfig({
|
|
title: "yt2press",
|
|
description: "video to vitepress",
|
|
themeConfig: {
|
|
// https://vitepress.dev/reference/default-theme-config
|
|
nav: [{ text: "Home", link: "/" }],
|
|
|
|
sidebar: [
|
|
{
|
|
text: "Preview",
|
|
// items: [
|
|
// { text: 'Markdown Examples', link: '/markdown-examples' },
|
|
// { text: 'Runtime API Examples', link: '/api-examples' }
|
|
// ]
|
|
},
|
|
],
|
|
|
|
socialLinks: [
|
|
{ icon: "github", link: "https://git.polv.cc/polv/yt2press" },
|
|
],
|
|
},
|
|
markdown: {
|
|
image: {
|
|
lazyLoading: true,
|
|
},
|
|
config(md) {
|
|
// production-only gate
|
|
const isProd =
|
|
process.env.NODE_ENV === "production" ||
|
|
process.env.VITEPRESS_ENV === "production"; // extra safety
|
|
|
|
if (isProd) {
|
|
md.core.ruler.push("rewrite-image-urls", (state) => {
|
|
if (!state.tokens) return;
|
|
|
|
for (const token of state.tokens) {
|
|
if (token.type !== "inline") continue;
|
|
|
|
for (const child of token.children ?? []) {
|
|
// images: 
|
|
if (
|
|
child.type === "image" &&
|
|
typeof child.attrGet("src") === "string"
|
|
) {
|
|
const src = child.attrGet("src");
|
|
|
|
// rewrite only /images/* (adjust if your paths differ)
|
|
if (src && src.startsWith("/images/")) {
|
|
child.attrSet("src", `${IMG_ORIGIN}${src}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
},
|
|
vite: {
|
|
clearScreen: false,
|
|
server: {
|
|
// make sure this port matches the devUrl port in tauri.conf.json file
|
|
port: 5173,
|
|
// Tauri expects a fixed port, fail if that port is not available
|
|
strictPort: true,
|
|
// if the host Tauri is expecting is set, use it
|
|
host: host || false,
|
|
watch: {
|
|
// tell vite to ignore watching `src-tauri`
|
|
ignored: ["**/src-tauri/**"],
|
|
},
|
|
proxy: {
|
|
"/socket": {
|
|
target: "ws://localhost:8080",
|
|
ws: true,
|
|
rewriteWsOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
// Env variables starting with the item of `envPrefix` will be exposed in tauri's source code through `import.meta.env`.
|
|
envPrefix: ["VITE_", "TAURI_ENV_*"],
|
|
build: {
|
|
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
|
|
target:
|
|
process.env.TAURI_ENV_PLATFORM == "windows" ? "chrome105" : "safari13",
|
|
// don't minify for debug builds
|
|
minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false,
|
|
// produce sourcemaps for debug builds
|
|
sourcemap: !!process.env.TAURI_ENV_DEBUG,
|
|
},
|
|
},
|
|
});
|