npm chokidar로 style 코드 찾는방법

npm chokidar로 style 코드 찾는방법

QA

npm chokidar로 style 코드 찾는방법

답변 2

본문

npm install chokidar로 설치는 했는데 

 

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

 

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

이 질문에 댓글 쓰기 :

답변 2

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

 

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}`);
 

 

 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 129,108
© SIRSOFT
현재 페이지 제일 처음으로