options = {
poll=10, //每秒轮询几次默认值为10
monitorTimeChange:false, //通过监听文件修改时间来判断文件是否发生变化(只要保存就调用回调函数)
//默认值为false
}
options = {
poll=10, //每秒轮询几次默认值为10
monitorTimeChange:false, //通过监听文件修改时间来判断文件是否发生变化(只要保存就调用回调函数)
//默认值为false
deep:false//是否开启深度监视
}
const watchAPI = require('watch-ysy')
watchAPI.watchFile(path,function(data){
//每次文件发生变化 删除 时会调用这个回调函数传入数据
{
type:Symbol('REDUCED')/*删除*/||Symbol('INCREASED')/*增加*/,
//其他信息...
}
},options,function(cancel){
//cancel可以取消监听
})
const cancel = watchAPI.watchFileSync(path,function(data){
},options)
//如果你想取消监听则执行cancel即可
watchAPI.watchDir(pathDir,data=>{},options,cancel=>{})
const cancel = watchAPI.watchDirSync(path,data=>{},options)
watchAPI.watch(path,data=>{},options,cancel=>{})
//如果你想指定多个路径
watchAPI.watch(['./a','./b'],data=>{},options,cancel=>{})
//如果你想指定多个options
watchAPI.watch([
{path:'./a',options:{deep:true},
...,
{path:'./b',options:{deep:false}}
],
data=>{},
options,
cancel=>{}
)
cancel = watchAPI.watchSync(path,data=>{},options)
//如果你想指定多个路径
cancel = watchAPI.watchSync(['./a','./b'],data=>{},options)
//如果你想指定多个options
cancel = watchAPI.watchSync([
{path:'./a',options:{deep:true},
...,
{path:'./b',options:{deep:false}}
],
data=>{},
options,
)