问题描述
我正在使用 MERN 堆栈开发应用程序。后端和前端在具有此层次结构的同一存储库中:
my-project/
├── backend/
│ │
│ .
│ .
│ └── package.json
├── frontend/
│ │
│ .
│ .
│ └── package.json
├── shared/
│ ├── constants/
│ .
│ .
│ ├── index.js
│ └── package.json
├── package.json
└── README.md
我希望在后端和前端之间共享我的常量。我在共享文件夹/模块中有常量。
我还希望共享包中的任何更改都反映在其他包中,而无需重新安装。
后端和前端使用共享包作为依赖的最佳方式是什么?
解决方法
您的目录结构几乎可以使用。但可能有一些缺陷,
my-project/
├── backend/
│ │
│ .
│ .
│ └── package.json
├── frontend/
│ │
│ .
│ .
│ └── package.json
├── shared/
│ ├── constants/
│ .
│ .
│ ├── index.js
│ └── package.json // You might not need this
├── package.json // define shared packages here
└── README.md
更多细节,如何节点