Files
QZMusic_PC/amll-local/packages/react-full/tsdown.config.ts
lqtmcstudio 72f4510dc8 fork(fix): Clone AMLL 并修复 BUG
- 将AMLL Clone到本以地进行修复和优化(emm虽然这很不优雅但是暂时无时间做子模块和Fork)
- 修复在当前播放歌词行不可见的视口Seek会出现滚动偏移的问题
2026-06-07 00:02:14 +08:00

68 lines
1.8 KiB
TypeScript

import { readFileSync } from "node:fs";
import path from "node:path";
import pluginBabel from "@rolldown/plugin-babel";
import { transform } from "@svgr/core";
import { defineConfig } from "tsdown";
import { baseConfig } from "../../tsdown.base.ts";
const svgrQueryPlugin = {
name: "svgr-react-query",
resolveId(id: string, importer: string | undefined) {
if (id.endsWith("?react")) {
const rawPath = id.slice(0, -6);
const base = importer ? `file://${importer}` : `file://${process.cwd()}/`;
const resolved = new URL(rawPath, base).pathname.replace(
/^\/([A-Za-z]:)/,
"$1",
);
return `\0svgr:${resolved}`;
}
},
async load(id: string) {
if (id.startsWith("\0svgr:")) {
const file = id.slice(6);
const svg = readFileSync(file, "utf-8");
const code = await transform(
svg,
{ ref: true, plugins: ["@svgr/plugin-jsx"] },
{ filePath: file },
);
return { code, moduleType: "jsx" };
}
},
};
const cssUrlSvgInlinePlugin = {
name: "css-url-svg-inline",
transform(code: string, id: string) {
if (!id.endsWith(".css")) return;
const replaced = code.replace(
/url\(\s*(['"]?)([^)'"]+\.svg)\1\s*\)/g,
(_, _quote, svgPath) => {
const resolved = path.resolve(path.dirname(id), svgPath);
const svg = readFileSync(resolved, "utf-8");
const encoded = encodeURIComponent(svg);
return `url("data:image/svg+xml,${encoded}")`;
},
);
return replaced !== code ? { code: replaced } : undefined;
},
};
export default defineConfig({
...baseConfig,
entry: { "amll-react-framework": "./src/index.ts" },
plugins: [
cssUrlSvgInlinePlugin,
svgrQueryPlugin,
pluginBabel({
plugins: [
["babel-plugin-react-compiler", { target: "19" }],
"jotai-babel/plugin-debug-label",
"jotai-babel/plugin-react-refresh",
],
}),
],
});