Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: vite-node + HMR 적용 #591

Merged
merged 5 commits into from Jul 31, 2023
Merged

perf: vite-node + HMR 적용 #591

merged 5 commits into from Jul 31, 2023

Conversation

scarf005
Copy link
Member

@scarf005 scarf005 commented Jul 19, 2023

개요

2023-07-19.14-09-54.mp4
  • 코드 수정 후 0.5초 내로 재시작이 가능합니다. (기존 재시작 시간: 3~4초, perf: 백엔드 핫 리로딩 성능 벤치마크 #537 참고)
  • backend/ 코드 뿐만 아니라 모노레포의 contracts/ 패키지가 수정되어도 적용되는 것을 볼 수 있습니다. (contracts/에서 pnpm dev로 먼저 패키지를 실시간으로 빌드하도록 해야 합니다)

변경점

  • 전체 프로젝트를 es 모듈을 사용하도록 변경했습니다.
  • nodemon + ts-node를 vite-node로 변경했습니다.
  • 기존 방식 그대로, pnpm dev로 실행 가능합니다

기타

@scarf005 scarf005 force-pushed the ts-rest-v2 branch 5 times, most recently from 8c1f1d7 to c44d06b Compare July 26, 2023 05:39
Base automatically changed from ts-rest-v2 to develop July 26, 2023 08:25
@scarf005 scarf005 temporarily deployed to development July 30, 2023 13:51 — with GitHub Actions Inactive
@scarf005 scarf005 temporarily deployed to development July 30, 2023 14:44 — with GitHub Actions Inactive
@scarf005 scarf005 marked this pull request as ready for review July 30, 2023 14:48
@scarf005 scarf005 temporarily deployed to development July 30, 2023 23:50 — with GitHub Actions Inactive
Copy link
Contributor

@nyj001012 nyj001012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@scarf005 scarf005 temporarily deployed to development July 31, 2023 08:21 — with GitHub Actions Inactive
@scarf005 scarf005 mentioned this pull request Jul 31, 2023
Copy link
Member

@jimin52 jimin52 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -29,6 +29,7 @@ services:
container_name: backend
build:
context: .
entrypoint: ["./node_modules/.bin/vite-node", "src/server.ts"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entrypoint 를 Dockerfile 이 아닌 docker-compose 파일에서 실행해야 하나요?
궁금해서 질문드립니다.

Copy link
Member Author

@scarf005 scarf005 Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

도커파일에 ENTRYPOINT를 사용해도 문제는 없습니다.

backend/Dockerfile

Lines 18 to 24 in e9fac6d

FROM workspace as prod
ADD . ./
RUN pnpm -r install --frozen-lockfile --offline
RUN pnpm -r run build
WORKDIR /app/backend

다만 도커파일에서는 ENTRYPOINT의 값이 변할 때마다 마지막 단계 캐싱이 무효화되어 해당 단계를 다시 빌드해야 하는 문제가 있었습니다. 이를 해결하기 위해 포트나 환경 변수 파일처럼, 컴포즈 파일에서 엔트리포인트를 관리하도록 변경했습니다.

Comment on lines +13 to +16
"start": "npx vite-node src/server.ts",
"build": "pnpm --filter='@jiphyeonjeon-42/contracts' build",
"dev": "nodemon --watch src --watch ../contracts/dist --exec ts-node src/server.ts",
"prod": "pnpm build && pnpm start",
"dev": "vite-node --watch src/server.ts",
"standalone": "npm run build && npm run start",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경된 명령어에 대해 어딘가 설명을 남겨주시면 감사드리겠습니다.
주석이나 README 혹은 docs 면 좋을 것 같습니다.

@scarf005 scarf005 merged commit a8c3bd7 into develop Jul 31, 2023
3 checks passed
@scarf005 scarf005 deleted the vite-hmr branch July 31, 2023 13:05
nyj001012 pushed a commit that referenced this pull request Jul 31, 2023
* build: vite 추가

* build: vite + esm 모듈로 전환

* build: nodemon, ts-node 제거

* fix: entities를 named export로 변경

* perf: hmr 적용

---------

Co-authored-by: nocontribute <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 완료
Development

Successfully merging this pull request may close these issues.

None yet

3 participants