staticCopy(options)
ts
staticCopy({
targets: [
{ src: "LICENSE", dest: "meta/LICENSE" },
{
src: "robots.template.txt",
dest: "robots.txt",
transform: (content) => content.toString("utf8").replaceAll("{{HOST}}", "example.com"),
},
],
missing: "warn",
});dest 始终相对于 Vite outDir,越界路径会被拒绝。transform 仅支持普通文件;目录通过 Node.js 原生递归复制处理。
staticCopy 文件复制
在 Vite 写出构建产物后复制许可证、robots.txt 或其他静态目录。
签名
ts
export function staticCopy(options: StaticCopyPluginOptions): Plugin;示例
ts
import { staticCopy } from "fast-vite-plugins";
const plugin = staticCopy({ targets: [{ src: "public/robots.txt", dest: "meta/robots.txt" }] });
export default { plugins: [plugin] };输入
| 输入值 | 输入值类型 | 必填/默认值 | 输入值说明 |
|---|---|---|---|
options | StaticCopyPluginOptions | 是 | 复制目标及源路径缺失时的处理方式。 |
返回
| 返回值 | 返回值类型 | 返回值说明 |
|---|---|---|
plugin | Plugin | 可直接加入 Vite plugins 的静态复制插件。 |
