Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
},
......
like image 316
TechnicalKeera Avatar asked Aug 14 '18 18:08

TechnicalKeera


People also ask

How do I run Nextjs project locally?

Automatic Setup After the installation is complete: Run npm run dev or yarn dev or pnpm dev to start the development server on http://localhost:3000. Visit http://localhost:3000 to view your application. Edit pages/index.js and see the updated result in your browser.

Does Nextjs need a server?

You don't need a node server running 24/7 for hosting your application. Also, if you don't use getServerSideProps, Next. js by default will pre-render your page, this page gets cached on a CDN. So yes you can make API calls to your PHP backend, without the need for a setting up a nodejs server yourself.

How scalable is next JS?

Next. js makes it easy to scale multiple pages because it can individually select how to render each page either on the client, the server, or hybrid.


1 Answers

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.

like image 152
TechnicalKeera Avatar answered Sep 24 '22 21:09

TechnicalKeera