awh*_*who 5 javascript next.js
当我在本地运行时,我有一个pages/index.js可用的。localhost:3000next
我想运行next build && next export此页面并将其部署到 Gitlab Pages。由于 Gitlab Pages(或 Github Pages)的工作方式,我的页面应该可以被https://my-username.gitlab.io/my-nextjs-project/. 但由于/my-nextjs-project/URL 中出现此段,我无法成功将我的应用程序部署到 Gitlab Pages。
如果这是一个简单的 React 应用程序,我会设置output.publicPathin webpack.config.js。next.js 中的类比是什么output.publicPath?或者,您是否知道部署到 Gitlab/Github Pages 的公共项目,以便我可以检查它们的配置?
谢谢你!
在 next.config.js 上添加 assetPrefix。将其设置为 assetPrefix: 'test' 将测试所有内容
module.exports = {
// some configuration
assetPrefix: isProduction ? '/{reponame}' : '',
// another configuration
}
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助,这里有来自 Next.js 的链接,介绍如何将其部署到 GitHub 页面。https://github.com/zeit/next.js/wiki/Deploying-a-Next.js-app-into-GitHub-Pages