我们采用了以下项目 struct
|- pages
|- <page_name>
|- index.js # To do a default export of the main component
|- MainComponent.jsx # Contains other subcomponents
|- main-component.css # CSS for the main component
|- OtherComponents.jsx # more than 1 file for child components that are used only in that page
|- __tests__ # Jest unit and snapshot tests
|- components
|- index.js # Exports all the default components of each component as named exports
|- CommonCmpnt1
|- CommonCmpnt1.jsx
|- common-cmpnt-1.css
|- index.js # To default export the component
|- __tests__
|- CommonCmpnt2
|- CommonCmpnt2.jsx
|- common-cmpnt-2.css
|- index.js # To default export the component
|- __tests__
要澄清的是,没有任何东西坏了,而且它运行得非常好.我们在components
目录中的多个页面中重用了组件,我们在其中导入如下内容
// Assuming we are inside MainComponent.jsx
// ...
import { CommonCmpnt1 } from '../../components'; // We even take it a step further and use absolute imports
此外,只使用一次的组件并排放置在它的pages
文件夹中.
The only problem we face now is热模块重新加载被 destruct ,即每当我们在pages
或components
目录中编辑.jsx
文件时,我们必须手动重新加载页面以查看影响的更改(它不会影响CSS文件).这是我们已经习惯的事情,因此不会对我们造成严重影响.
我的问题是,有没有我们不知道的即将到来的灾难?