watchStaticFile()v4.0.61
note
此 API 正在迁移到 @remotion/studio
包。建议从 @remotion/studio
导入 API,而不是 remotion
。
监视特定静态文件的更改,并在文件更改时调用回调函数,从而在您的 Remotion 项目中实现动态更新。
warning
此功能仅在 Remotion Studio 环境中可用。在播放器中,事件将永远不会触发。
示例
example.tsxtsx
import {StaticFile ,watchStaticFile } from "remotion";// Watch for changes in a specific static fileconst {cancel } =watchStaticFile ("your-static-file.jpg",(newData :StaticFile | null) => {if (newData ) {console .log (`File ${newData .name } has been added or modified.`);} else {console .log ("File has been deleted.");}},);// To stop watching for changes, call the cancel functioncancel ();
example.tsxtsx
import {StaticFile ,watchStaticFile } from "remotion";// Watch for changes in a specific static fileconst {cancel } =watchStaticFile ("your-static-file.jpg",(newData :StaticFile | null) => {if (newData ) {console .log (`File ${newData .name } has been added or modified.`);} else {console .log ("File has been deleted.");}},);// To stop watching for changes, call the cancel functioncancel ();
参数
接受两个参数并返回一个可用于 cancel
事件侦听器的函数。
filename
要监视更改的 /public
文件夹中的文件名。
callback
当文件被修改时将调用的回调函数。作为参数传递 StaticFile
或 null
。