next.config.js: Introduction | Next.js

next.conifg.js

// next.config.js
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')

module.exports = (phase, { defaultConfig }) => {
  if (phase === PHASE_DEVELOPMENT_SERVER) {
    return {
      /* development only config options here */
    }
  }

  return {
    /* config options for all phases except development here */
  }
}

<aside> 💡 유의 사항 : next.config.js는 webpack, Babel, TS로 parse되지 않으니 최신 JS 문법을 쓰면 안된다.

</aside>

종류들

1. 환경변수

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

// pages 실제 쓰는곳
<Title>{proccess.env.customKey}</Title>

2. BasePath

module.exports = {
  basePath: '/docs',
}