채택완료

npm chokidar로 style 코드 찾는방법

npm install chokidar로 설치는 했는데 

 

파일수정시 style코드를 찾는 방법을 어떻게 활용해야하나요?

 

자바스크립트로 불러와도 에러가 나는데

|

답변 2개

채택된 답변
+20 포인트

https://github.com/paulmillr/chokidar 
chokidar 설치한곳에 예제코드로 test.js 파일 만드신다음 

shell 열어서 node test.js 실행해보세요

아래의 코드를 한번 참고해 보시겠어요..

 

const chokidar = require('chokidar');
const fs = require('fs');

// 감시할 파일 경로
const filePath = 'path/to/your/file.css';

// 파일 감시
const watcher = chokidar.watch(filePath, {
  persistent: true
});

// 파일 변경 이벤트 처리
watcher.on('change', path => {
  console.log(`File ${path} has been changed`);
  
  // 변경된 파일 내용 읽기
  fs.readFile(filePath, 'utf8', (err, data) => {
    if (err) {
      console.error(err);
      return;
    }
    
    // 변경된 파일 내용 출력 (또는 다른 처리)
    console.log('Updated file content:');
    console.log(data);
  });
});

// 감시 시작 메시지 출력
console.log(`Watching for file changes on ${filePath}`);
 

 

 

답변을 작성하려면 로그인이 필요합니다.