【问题标题】:Create-React-App build folder missing filesCreate-React-App 构建文件夹缺少文件
【发布时间】:2020-01-17 15:32:44
【问题描述】:

我已经运行 create-react-app 并开始开发我的应用程序。 yarn start 完美运行,应用程序在浏览器中运行,包含多个组件和导入的图像。但是,当我运行 yarn build 时,并非所有图像都移动到 build/static/media(请参见下图)。

Folder structure and terminal output

除了关于箭头功能的警告外,终端输出中没有错误,我已经删除但没有成功。

它是否仍在构建我只有全景图.jpg 时的旧版本?请指教。

【问题讨论】:

  • 我相信public文件夹中的所有文件都只是直接复制到build文件夹中。您是否正在运行任何手动任务来复制 src/img 文件夹?
  • 不,我已经多次删除 build 文件夹,只需按照自述文件中的说明运行 yarn build。这会导致您在图像中看到的内容。全景图.jpg 最终在构建文件夹中,但没有其他图像。
  • 尝试将所有图像放在public 文件夹中一次。检查这是否有效?
  • 这会导致以下错误Module not found: You attempted to import ../../../../../public/img/panorama.jpg which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
  • 使用 /img/panorama.jpg 而不是相对路径导入。公共文件夹中的任何内容都应以/ 开头,然后是公共相对路径。

标签: reactjs create-react-app


【解决方案1】:

你需要把你的图片放到 /public 文件夹中。

【讨论】:

    猜你喜欢
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 2018-11-16
    • 2017-12-06
    • 2019-10-05
    • 1970-01-01
    相关资源
    最近更新 更多