[英]How to deploy next.js app to Gitlab / Github Pages?
I have a pages/index.js
which is available at localhost:3000
when I run locally next
.我有一个pages/index.js
,当我next
在本地运行时,它在localhost:3000
可用。
I want to run next build && next export
and deploy this page to Gitlab Pages.我想运行next build && next export
并将此页面部署到 Gitlab Pages。 Due to how Gitlab Pages (or Github Pages for that matter) work, my page should be accessible to https://my-username.gitlab.io/my-nextjs-project/
.由于 Gitlab 页面(或 Github 页面)的工作方式,我的页面应该可以访问https://my-username.gitlab.io/my-nextjs-project/
。 But because of this segment /my-nextjs-project/
that appears in the URL, I wasn't able to successfully deploy my app to Gitlab Pages.但是由于 URL 中出现的这个段/my-nextjs-project/
,我无法将我的应用程序成功部署到 Gitlab Pages。
If this would be a simple React app, I would set the output.publicPath
in webpack.config.js
.如果这是一个简单的 React 应用程序,我会在output.publicPath
中设置webpack.config.js
。 What's the analog of output.publicPath
in next.js? output.publicPath
中 output.publicPath 的模拟是什么? Or, do you know a public project deployed to Gitlab/Github Pages so I can check their configuration?或者,您知道部署到 Gitlab/Github Pages 的公共项目以便我可以检查它们的配置吗?
Thank you!谢谢!
On your next.config.js add assetPrefix.在你的 next.config.js 添加 assetPrefix。 Setting it up to assetPrefix: 'test' will put everything under test将其设置为 assetPrefix: 'test' 将测试所有内容
module.exports = {
// some configuration
assetPrefix: isProduction ? '/{reponame}' : '',
// another configuration
}
Hope this helps, here is a link from Next.js on how to deploy it to GitHub pages.希望这会有所帮助,这里有一个来自 Next.js 的关于如何将它部署到 GitHub 页面的链接。 https://github.com/zeit/next.js/wiki/Deploying-a-Next.js-app-into-GitHub-Pages https://github.com/zeit/next.js/wiki/Deploying-a-Next.js-app-into-GitHub-Pages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.