preBuild 가 appRoot 에서 돌아서 cd ../../ 로 루트로 올라가 설치하고, AMPLIFY_MONOREPO_APP_ROOT(= appRoot)1 로 앱 경로를 되짚는다.

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            # AWS Amplify 에서 모노레포 구조를 사용 할 경우 root 레벨로 올라가서 install
            - cd ../../
            - echo "$PWD"
            - yarn install
        build:
          commands:
            - echo "$PWD"
            # 현재 root로 이동한 상태이므로 $AMPLIFY_MONOREPO_APP_ROOT를 바로 참조하도록 설정
            - if [ $NODE_ENV_VARIABLES = ".env.development" ]; then cat "./$AMPLIFY_MONOREPO_APP_ROOT/$NODE_ENV_VARIABLES" > "./$AMPLIFY_MONOREPO_APP_ROOT/.env.production"; fi
            - yarn run "build:$AMPLIFY_MONOREPO_APP"
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    appRoot: apps/app

Footnotes

  1. Configuring monorepo build settings - AWS Amplify Hosting: appRoot — “This key must exist, and have the same value as the AMPLIFY_MONOREPO_APP_ROOT environment variable.” ↩

#231

How To Maintain A Large Next.js Application — Smashing Magazine

  • TypeScript 사용
  • Lerna , Nx , Rush , Turborepo , yarn workspaces를 사용하여 Mono-Repo 구조 사용
  • Hygen과 같은 코드 생성기를 사용하여 상용구 코드 생성
  • Redux 툴킷을 통해 하위 상용구와 함께 Redux와 같이 잘 설정된 패턴 사용
  • 비동기 데이터를 가져오기 위해 React 쿼리 또는 SWR 사용
  • Husky와 함께 Commitizen 및 Semantic Release 사용
  • UI 구성 요소 시각화를 위해 스토리북 사용
  • 처음부터 유지 관리 가능한 테스트 작성
  • Dependabot을 사용하여 자동으로 패키지 업데이트
  • Production Checklist | Next.js
#48
# 특정 패키지에 모듈을 설치해야한다면
yarn workspace <workspace_name> <command>

<command> 자리에 아무 Yarn 명령이나 오고 그 워크스페이스 안에서 돈다 — add 면 그 패키지의 package.json 에 들어간다.1


Footnotes

  1. yarn workspace | Yarn: “This will run the chosen Yarn command in the selected workspace.” / yarn workspace awesome-package add react react-dom --dev — “will add react and react-dom as devDependencies in your packages/awesome-package/package.json.” ↩

#66