Gatsby 项目在 webpack 问题的目录中
我有一个 gatsby 项目,当我将它放在域的根目录中时,它工作得很好(例如 abc.com)。但如果我将它放在一个目录下(例如 abc.com/myproj),那么 webpack 等会抛出 404 错误,因为它们仍然引用项目的根目录。
是否可以修复此问题并让他们查找 myproj 目录中的所有 js 文件而不是查看根目录?
是否需要更改任何配置才能在根目录下的目录中工作?提前致谢。
I have a gatsby project and when I put it in the root of the domain it works just fine (e.g. abc.com). But if I place it under a directory (e.g. abc.com/myproj) then the webpack ect throwing 404 error as they are still referring to the root of the project.
Could this be fixed and make them look for all js files inside the myproj
directory instead of looking at the root?
is there any configurations I need to change it to work inside a directory under the root? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找 路径前缀。只需在
gatsby-config.js
中添加以下内容:要启用完整配置,您需要将构建和服务命令调整为:
并且:
在这两种情况下,如果未传递该标志,Gatsby将忽略
pathPrefix
。对于手动构建的路径名,有一个辅助函数
withPrefix
在生产环境中添加路径前缀(但在开发过程中不需要添加路径前缀)加上前缀)。I think you are looking for path prefixing. Just add the following in your
gatsby-config.js
:To enable the full configuration you will need to tweak your build and serve command as:
And:
In both cases, if the flag is not passed, Gatsby will ignore the
pathPrefix
.For pathnames you construct manually, there’s a helper function,
withPrefix
that prepends your path prefix in production (but doesn’t during development where paths don’t need to be prefixed).