Skip to content

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] };

输入

输入值输入值类型必填/默认值输入值说明
optionsStaticCopyPluginOptions复制目标及源路径缺失时的处理方式。

返回

返回值返回值类型返回值说明
pluginPlugin可直接加入 Vite plugins 的静态复制插件。