I
I
Ivan Ivanovich2021-04-07 15:04:53
React
Ivan Ivanovich, 2021-04-07 15:04:53

How to configure config in next?

Good day.

The original config was:

module.exports = {
  async redirects() {
    return [
      {
        source: '/signup',
        destination: '/sign-up',
        permanent: true,
      },
    ];
  },
};


But now I want to add:

module.exports = (phase) => {
  if (phase === PHASE_DEVELOPMENT_SERVER) {
    return {
      env: {
        test: 'hello',
      },
    };
  }

  return {
    env: {
      test: 'hello world',
    },
  };
};


If you just combine all this into one file, the redirect will not work.

Can you please tell me how to combine these two functions in the next.config.js config?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Ivanovich, 2021-04-12
@IwanQ

module.exports = (phase, { defaultConfig }) => {
  if (phase === PHASE_DEVELOPMENT_SERVER) {
    return {
      ...defaultConfig,
      future: {
        webpack5: true,
      },
      redirects: async () => {
        return [
          {
            source: '/sign-up',
            destination: '/signup',
            permanent: true,
          },
        ];
      },
      env: {
        test: 'hello',
      },
    };
  }

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

https://github.com/vercel/next.js/blob/canary/pack...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question