【问题标题】:My website images are not loading from the correct link on Github Pages with Gatsby我的网站图片没有从带有 Gatsby 的 Github Pages 上的正确链接加载
【发布时间】:2020-07-26 20:44:22
【问题描述】:

该网站是使用部署在 Github Pages 上的 Gastby 构建的。我的图片的链接应该是https://eoja82.github.io/lakeside-demo/img/employees/jake.jpg。但是,链接类似于https://eoja82.github.io/img/employees/jake.jpg,省略了/lakeside-demo 部分。

我在我的 gastby-config.js 文件中使用pathPrefix

module.exports = {
  pathPrefix: "/lakeside-demo",
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-transformer-json`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `./src/components/products/data/`
      }
    },
  ]
}

我的 package.json 文件中有以下脚本: "deploy": "gatsby build --prefix-paths && gh-pages -d public"

我尝试过使用 Gatsby 的 withPrefixassetPrefix,但找不到任何可行的解决方案。

Github:https://github.com/eoja82/lakeside-demo
网址:https://eoja82.github.io/lakeside-demo/

任何建议将不胜感激!

【问题讨论】:

    标签: gatsby github-pages


    【解决方案1】:

    withPrefix 这样使用应该可以工作:

    <img className={styles.moreInfoImg} src={withPrefix("/img/loadedTruck.jpg")} alt="delivery truck" />
    

    【讨论】:

    • 谢谢,确实有效!如何让它与 css 背景图像一起使用?像&lt;div style={{ backgroundImage: `url(${withPrefix('/images/image.png')})` }} /&gt; 这样的内联样式是最好的方法吗?在这里看到了这个例子:stackoverflow.com/a/61404226/11444813
    猜你喜欢
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    相关资源
    最近更新 更多