最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Build NextJS Project on Local without Now - Stack Overflow

programmeradmin5浏览0评论

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

I R & D on it, everyone remend 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"
},
......

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

I R & D on it, everyone remend 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"
},
......
Share Improve this question edited Aug 14, 2018 at 18:05 TechnicalKeera asked Aug 14, 2018 at 18:00 TechnicalKeeraTechnicalKeera 1,07811 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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 plete required mand to build NextJS project. So after adding this into package.json you just need to run in terminal: npm export and it will generate plete build for nextjs project.

You have a package.json script called build that runs next build. The next build mand 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.

发布评论

评论列表(0)

  1. 暂无评论