将图像文件(.jpg,.png)放入react static boilerplate
如何在组件内部使用它们?
答案 0 :(得分:0)
通常,静态文件,图像等存储在./public/
文件夹中。如果将图像存储在该文件夹中会更好。您可以在./public/
文件夹中使用另一个单独的文件夹,例如images
。
如果您浏览了文档页面,那就很清楚了。这是文件夹结构。请参阅粗体部分。
.
├── /components/ # Shared or generic UI components
│ ├── /Button/ # Button component
│ ├── /Layout/ # Website layout component
│ ├── /Link / # Link component to be used instead of <a>
│ └── /... # etc.
├── /core/ # Core framework
│ ├── /history.js # Handles client-side navigation
│ ├── /router.js # Handles routing and data fetching
│ └── /store.js # Application state manager (Redux)
├── /node_modules/ # 3rd-party libraries and utilities
├── /pages/ # React components for web pages
│ ├── /about/ # About page
│ ├── /error/ # Error page
│ ├── /home/ # Home page
│ └── /... # etc.
├── /public/ # Static files such as favicon.ico etc.*
│ ├── /dist/ # The folder for compiled output
│ ├── favicon.ico # Application icon to be displayed in bookmarks
│ ├── robots.txt # Instructions for search engine crawlers
│ └── /... # etc.
├── /test/ # Unit and integration tests
├── /utils/ # Utility and helper classes
│── main.js # React application entry point
│── package.json # The list of project dependencies and NPM scripts
│── routes.json # This list of application routes
│── run.js # Build automation script, e.g. `node run build`
└── webpack.config.js # Bundling and optimization settings for Webpack