https://www.jianshu.com/p/23b5e604268d
nodejs下监听文件更改的插件
var path = require(‘path‘) var Chokidar = require(‘chokidar‘); var watcher = Chokidar.watch([path.join(__dirname, ‘../src‘)], { // ignored: /(^|[\/\\])\../, persistent: true, usePolling: true, }); var log = console.dir.bind(console); var watchAction = function({event, eventPath}){ log(`Has been ${event}ed, file: ${eventPath}`); // 这里进行文件更改后的操作 } watcher .on(‘ready‘, () => log(`Initial scan complete. Ready for changes.`)) .on(‘add‘, path => log(`File ${path} has been added`)) .on(‘change‘, path => watchAction({event: ‘change‘, eventPath: path})) .on(‘unlink‘, path => watchAction({event: ‘remove‘, eventPath: path}));
原文地址:https://www.cnblogs.com/samxiong/p/10970053.html
时间: 2024-10-07 23:23:30