.env 파일 사용 방법 .local dev(development)...etc...

kkikki·2024년 11월 27일

자신의 프로젝트 루트 경로에 파일을 생성

.env.local
.env.production
.env.test
.env.dev
.env.development
... 등등

package.json에 있는 scripts를 보면, 자신이 생성한 환경 변수에 따라 빌드 할 수 있습니다.


{
  "scripts": {
    "start": "cross-env NODE_ENV=development dotenv -e .env.development -e .env -- react-scripts start",
    "build": "cross-env NODE_ENV=production dotenv -e .env.production -e .env.development -- react-scripts build",
    "test": "cross-env NODE_ENV=test dotenv -e .env.test -e .env -- react-scripts test"
  },
  "devDependencies": {
    "cross-env": "^7.0.3",
    "dotenv-cli": "^7.0.0"
  }
}

또다른 예

  "start": "export PORT=8888 && env-cmd -f .env.local react-scripts start",
    "build": "env-cmd -f .env.dev react-scripts build",
profile
도전을 멈추지 않고 keep going 하는 개발자입니다 👣🏃🏻‍➡️ 주로 트러블 슈팅 위주로 작성해두지만, 시간나면 멋진 글을 적어보겠습니다....!

0개의 댓글