【发布时间】:2018-07-14 04:28:53
【问题描述】:
使用 create-react-app 时,我的 images 文件夹应该在哪个目录下?
在src 或public?
当我准备好运行yarn build 时,其中一个会出现问题吗?
我听说只有放在public 目录中的文件会在构建后加载。 对还是错?
我猜 React 团队在 index.html 上的这条评论让我感到困惑。
<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`.
-->
编辑: 阅读下面的 cmets 后,这就是我在 src 文件夹中的图像文件夹的结构。
你能告诉我这是否是一个好的/最佳实践吗?
**Images Component**
import Foo from "./images/foo.jpg";
import Bar from "./images/bar.jpg";
import './styles/Images.css';
export const Logo = () => (
<img src={Foo} alt="bla bla" />
)
export const Profile = () => (
<img src={Bar} alt="bla bla" />
)
我想使用图像的组件。
import { Logo, Profile } from './Images';
const Home = () => (
<div>
<Logo/>
<Profile/>
</div>
)
【问题讨论】:
标签: javascript reactjs npm create-react-app yarnpkg