3

Originally, I had my distDir set to a folder within my Firebase Functions directory for deployment, however, the duplication of React when running the app in dev mode led to some errors, so I've had to comment it out.

Is there a way to specify the next build commands output directory within the command? Like next build dir='../functions/next'.

Or is there a way to separate dev builds directory (from the next command) from the production builds (next build) within the config?

asked Dec 1, 2019 at 0:23

2 Answers 2

11

I found following solution for this problem:

You can set custom environment variable that decides where your build will be generated:

BUILD_DIR=myBuilds/buildXYZ yarn build

OR

BUILD_DIR=myBuilds/buildXYZ npm build

In the next.config.js you can use your environment variable like this:

module.exports = {
 distDir: process.env.BUILD_DIR || '.next',
}

Now your build will be dynamically generated in the myBuilds/buildXYZ directory defined in the BUILD_DIR variable.

One thing to notice: If you want to use the next export command (or any other command using the build directory), you should also add the environment variable before it, e.g.:

BUILD_DIR=myBuilds/buildXYZ yarn export
Bassem
4,1804 gold badges26 silver badges55 bronze badges
answered Jan 29, 2021 at 11:56
Sign up to request clarification or add additional context in comments.

1 Comment

ENV" must be lower case. module.exports = { distDir: process.env.BUILD_DIR || '.next', }
0

According to https://github.com/zeit/next.js/issues/1513, this may need you to update to the next version. But it looks like they added a feature to next.config.js file. All you have to do is add the destination for your dist:

module.exports = {
 options: {
 dist: '.next'
 }
}

Haven't tested it, but it was successfully merged to master and marked as resolved.

answered Dec 1, 2019 at 1:04

1 Comment

That's not the solution that was just a feature request.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.