简体   繁体   English

如何构建next.js文件并上传到linux共享主机

[英]how to build next.js files and upload to linux shared hosting

I have a project done using next.js and reactjs .我有一个使用next.jsreactjs完成的项目。 I have used next.js with reactjs for SSR .我已经将 next.js 与 reactjs 一起用于SSR

Now the problem is I cannot build the project.现在的问题是我无法构建项目。 If I build ( next build , next export ), the generated index.html shows only the first page and other page links are not working.如果我构建(下一个构建下一个导出),生成的 index.html 只显示第一页,其他页面链接不起作用。 How to build the project and generate the files.如何构建项目并生成文件。 Is it possible.是否可以。

I have a linux shared hosting .我有一个linux 共享主机 Is next.js works in linux shared hosting . next.js是否适用于linux 共享主机 Please guide me through.请指导我通过。 I am new to next.js .我是next.js 的新手

package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "export": "next export",
    "start": "next start"
  },
  "dependencies": {
    "next": "9.1.6",
    "react": "16.12.0",
    "react-dom": "16.12.0"
  }
}

next.config.js

module.exports = {
  exportTrailingSlash: true,
  exportPathMap: function() {
    return {
      '/': { page: '/' }
    };
  }
};

Your exportPathMap is specifically telling Next to only build the index.js file.您的exportPathMap专门告诉 Next 只构建 index.js 文件。 You only need to include exportPathMap if you need to customize the build.如果您需要自定义构建,则只需要包含exportPathMap If you exclude it, it will build everything in your pages directory.如果您排除它,它将在您的pages目录中构建所有pages If you include it, you can merge it with the default parameter that comes into that function (which will have all those pages files), or you can write your own (like you have done) to tell Next exactly what to build.如果包含它,您可以将它与进入该函数的默认参数(将包含所有这些pages文件)合并,或者您可以编写自己的(就像您所做的那样)来告诉 Next 确切地构建什么。

So if your pages were coming from a server (like from a CMS), you would use exportPathMap to ping the server and tell Next what pages to build.因此,如果您的页面来自服务器(例如来自 CMS),您将使用exportPathMap ping 服务器并告诉 Next 要构建哪些页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM