reactjs - WebStorm 上的 %PUBLIC_URL% 编辑器警告

标签 reactjs intellij-idea webstorm create-react-app

带有 create-react-app 的 WebStorm 在 /public/index.html 中有文件,到 /public 的文件夹路径标记为 %PUBLIC_URL% .

找不到目录%PUBLIC_URL%因为它不存在,也不应该存在。

除了用 <!--suppress HtmlUnknownTarget --> 抑制错误之外, 有没有办法在 Webstorm 中为目录变量设置别名,如 %PUBLIC_URL% , 到 /public 的根路径在开发中没有编辑器错误?

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
    <!--
      manifest.json provides metadata used when your web app is added to the
      homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
</head>

最佳答案

这篇文章似乎对此提供了更多见解:
https://medium.com/@jenniferdobak/the-public-folder-and-favicons-in-create-react-app-8dc2cc1d492b

This is a good time to address that funky looking %PULIC_URL% tag. Remember the ‘escape hatch’ React provides in case we put assets in the public folder? During the build, assets prefixed with the %PULIC_URL% tag will be recognized and complied. However this is NOT best practice and should be used only when necessary.


因此,在大多数情况下,您可以将 %PUBLIC_URL% 替换为 public 之类的内容,当然,这取决于您如何构建 React 项目。

关于reactjs - WebStorm 上的 %PUBLIC_URL% 编辑器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50670349/

相关文章:

java - 正则表达式排除引号内的匹配项

javascript - 有没有一种简单的方法可以在 WebStorm 中评估 JavaScript?

javascript - 为什么我们需要中间件用于 Redux 中的异步流?

javascript - Reactjs:在 setState 中使用时 Obj 被重新分配,有些奇怪

javascript - typescript / react 。错误类型 '{ key: number; }' 不可分配给类型 ILink(SFC 组件)

javascript - 为什么我的部分没有被发现?

javascript - Webstorm 是否支持不同文件中的 Revealing-Module-Pattern 的自动建议

javascript - "field1:field2"是什么意思?

java - 如何在不使用 NullLayout 的情况下以循环方式在 JPanel 上定位对象?

intellij-idea - 当我使用自动格式时,是否有插件告诉 IntelliJ 不要格式化特定 block ?