Development/React.js

next.cofing.js 파일에서 환경변수를 설정하는 방법

moretz0921 2022. 4. 14. 23:13

next.cofing.js 파일에서 환경변수를 설정하는 방법
: 보안적 이슈로 인해 api 주소나 민감한 정보들은 클라이언트에서 노출되지 않도록 .env파일을 사용할 것 

 

설정 

// next.config.js 파일 
module.exports = {
  env: {
    customKey: 'my-value',
  },
}



- 사용할 때는 process.env.{key_name} 와 같이 접근해서 사용

// 코드에서 사용 
export default function Home() {

  //환경 변수
  const config = process.env.customKey;

  return (
    <div>
      <div>env variable in config file : {config}</div>
    </div>
  );
}

 

 

출처

https://intrepidgeeks.com/tutorial/nextjs-nextconfigjs

 

Next.js - next.config.js

next를 좀 더 커스텀하게 사용하기 위해 next.config.js 파일에서 기본 설정을 할 수 있다. next.config.js 는 JSON 파일이 아닌 일반 Node 모듈이고 next 서버 빌드 단계에서 사용되며 브라우저 빌드에는 포함

intrepidgeeks.com

 

'Development > React.js' 카테고리의 다른 글

next.config.js로 Redirects 설정  (0) 2022.04.14
next.config.js에서 base path를 설정  (0) 2022.04.14
next.config.js  (0) 2022.04.14
immer 라이브러리  (0) 2022.04.12
상태 관리 패턴의 분류  (0) 2022.04.12