TechnicalKeera
TechnicalKeera

Reputation: 1053

How to Build NextJS Project on Local without Now

I need to build My React NextJS Project on local to host it at Appache server, when I run command run build it did not generate build folder.

I R & D on it, everyone recommend ZEIT – Next.js build with Now but it build project on cloud but I need a build for my local appache server. So please help me out.

Here is an my of package.json:

......
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start"
},
......

Upvotes: 6

Views: 7837

Answers (2)

TechnicalKeera
TechnicalKeera

Reputation: 1053

After so many struggle, I found answer of my question I have to add following line in my package.json under scripts:

"scripts": {
    ......
    "export": "npm run build && next export"
    .....
},

Basically I my case, npm run build && next export was complete required command to build NextJS project. So after adding this into package.json you just need to run in terminal: npm export and it will generate complete build for nextjs project.

Upvotes: 4

Obed Parlapiano
Obed Parlapiano

Reputation: 3682

You have a package.json script called build that runs next build. The next build command by default builds the app for development, which doesn't create a production bundle.

In order to create the production bundle on your local machine, you need to specify that you're on production environment through NODE_ENV=production (this is done automatically in now and other deployment servers). Basically, your package.json would end up:

"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start",
"prod:build": "NODE_ENV=production npm run build"
},

You can replace npm run build with next build directly if you prefer that.

Upvotes: -1

Related Questions