如何从webpack 中的assets url 中删除后缀斜杠“/” | 盖茨比

Alq*_*diq 5 html javascript reactjs webpack gatsby

I am generating a build from webpack. But whenever it generates a build it creates an index.html file along with other files but in the index.html it adds script tags with the suffix "/". I want to add a configuration in webpack to just add the name of the files of different assets instead of the suffix "/"

My index.html:

<head>
  <meta charSet="utf-8" />
  <meta http-equiv="x-ua-compatible" content="ie=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
  <meta name="generator" content="Gatsby 2.1.19" />
  <link as="script" rel="preload" href="/component---src-templates-all-pokemon-js-d59d33d2742ee8d7199e.js" />
  <link as="script" rel="preload" href="/app-a6912420758bcc3e24a1.js" />
  <link as="script" rel="preload" href="/webpack-runtime-65c9ddc0802b64490fd8.js" />
  <link as="fetch" rel="preload" href="/static/d/382/path---index-6a9-UNWMCjcHKgbI17oOwICQKH7zPs.json"
    crossorigin="use-credentials" />
</head>
Run Code Online (Sandbox Code Playgroud)

But I want it like this for each and everything.

<head>
  <meta charSet="utf-8" />
  <meta http-equiv="x-ua-compatible" content="ie=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
  <meta name="generator" content="Gatsby 2.1.19" />
  <link as="script" rel="preload" href="component---src-templates-all-pokemon-js-d59d33d2742ee8d7199e.js" />
  <link as="script" rel="preload" href="app-a6912420758bcc3e24a1.js" />
  <link as="script" rel="preload" href="webpack-runtime-65c9ddc0802b64490fd8.js" />
  <link as="fetch" rel="preload" href="static/d/382/path---index-6a9-UNWMCjcHKgbI17oOwICQKH7zPs.json"
    crossorigin="use-credentials" />
</head>
Run Code Online (Sandbox Code Playgroud)

I know that I have to change my webpack configurations, but I am unable to do that for all the asset files in a Gatsby. I want to do it for each and every file I am loading from my browser.

Cyr*_*and 3

我认为没有任何方法可以删除开头的斜杠,但如果您的 gatsby 站点不是域的根目录,例如www.example.com/blog/您可以使用路径前缀。

\n\n

文档中

\n\n
\n

使用路径前缀构建站点有两个步骤。

\n\n
    \n
  1. 首先在您的 site\xe2\x80\x99s gatsby-config.js 中定义前缀。
  2. \n
\n\n

gatsby-config.js

\n\n
    module.exports = {\n        // Note: it must *not* have a trailing slash.\n        pathPrefix: `/blog`,\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n
    \n
  1. 然后将--prefix-pathscmd 选项传递给 Gatsby。

    \n\n

    gatsby build --prefix-paths

  2. \n
\n
\n