首页 > 解决方案 > 在 MERN 存储库中设置共享文件夹

问题描述

我正在使用 MERN 堆栈开发应用程序。后端和前端位于具有此层次结构的同一存储库中:

my-project/
├── backend/
│   │
│   .
│   .   
│   └── package.json
├── frontend/
│   │
│   .
│   .   
│   └── package.json
├── shared/
│   ├── constants/
│   .
│   .   
│   ├── index.js
│   └── package.json
├── package.json
└── README.md

我想让我的常量在后端和前端之间共享。我在共享文件夹/模块中有常量。

我还希望共享包中的任何更改都反映在其他包中,而无需重新安装。

后端和前端使用共享包作为依赖项的最佳方式是什么?

标签: javascriptnode.jsnpmmern

解决方案


您的目录结构几乎可以使用。但可能会有一些瑕疵,

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

更多细节,如何节点


推荐阅读