ESM(ES Modules) 방식 테스트 예제

이 예제는 npm run build를 실행하여 만들어진 통합 ES 모듈 배포본(dist/flowchart.js)을 사용합니다.

⚠️ 실행 시 주의사항 (CORS 제약):
브라우저 보안 정책상, 로컬 파일 시스템 주소(file:///...)로 이 HTML을 직접 더블 클릭하여 열면 모듈 import가 동작하지 않고 에러가 발생합니다.
반드시 로컬 개발 서버(npm run dev)를 구동한 상태에서 브라우저 주소창에 http://localhost:5173/test-app/example-esm.html을 입력하여 정상 동작을 확인해 주시기 바랍니다.

출력 결과 (Canvas)

1) C 언어 소스코드 로드 예시

코드

<canvas id="flowchartCanvasC"></canvas>
<script type="module">
  import { drawFlowchart } from '../dist/flowchart.js';
  const cCode = `
  if (a == 1) {
    print(a);
  } else {
    print(b);
  }
  `;
  const canvasC = document.getElementById('flowchartCanvasC');
  drawFlowchart(cCode, 'C', canvasC);
</script>

결과

2) Python 언어 소스코드 로드 예시

코드

<canvas id="flowchartCanvasPython"></canvas>
<script type="module">
  import { drawFlowchart } from '../dist/flowchart.js';
  const pyCode = `
if a == 1:
    print(a)
else:
    print(b)
  `;
  const canvasPy = document.getElementById('flowchartCanvasPython');
  drawFlowchart(pyCode, 'Python', canvasPy);
</script>

결과