简体   繁体   English

使用 lerna 为 react 和 node js web 应用程序实现 monorepo

[英]implementing monorepo for react and node js web application using lerna

i am trying to build a monorepo , which consist of a react and node js application so the frontEnd folder which is created using react app and backEnd folder which consist of all server code.我正在尝试构建一个 monorepo ,它由一个 react 和 node js 应用程序组成,因此前端文件夹是使用 react 应用程序创建的,而 backEnd 文件夹由所有服务器代码组成。

I have done the below steps我已经完成了以下步骤

installed lerna globally全球安装lerna

created a new folder and initialized the repository.创建了一个新文件夹并初始化了存储库。

inside the new folder run lerna init, which created 2 files lerna.json, package.json and 1 folder as packages.在新文件夹中运行 lerna init,它创建了 2 个文件 lerna.json、package.json 和 1 个文件夹作为包。

inside packages folder i run create-react-app frontEnd, it created a new react application在包文件夹中,我运行 create-react-app frontEnd,它创建了一个新的 React 应用程序

run the command mkdir backEnd, to created the backEnd folder in the packages folder运行命令 mkdir backEnd,在包文件夹中创建 backEnd 文件夹

now my packages folder consist of two folders frontEnd and backEnd.现在我的包文件夹由两个文件夹前端和后端组成。

the frontEnd consist of a package.json which comes with create-react-app前端由 create-react-app 附带的 package.json 组成

questions问题

Do i need to remove the package.json from the frontEnd folder我是否需要从前端文件夹中删除 package.json

how i configure the lerna.json and package.json in the root folder.我如何在根文件夹中配置 lerna.json 和 package.json。

how can i run the application?我如何运行应用程序?

i have searched but i am not getting the solution to make a react-nodejs application with lerna using create-react-app我已经搜索过,但我没有得到使用 create-react-app 使用 lerna 制作 react-nodejs 应用程序的解决方案

I did this task here我在这里完成这项任务

Do i need to remove the package.json from the frontEnd folder我是否需要从前端文件夹中删除 package.json

No, each project in the /packages folder may have its dependencies.不, /packages文件夹中的每个项目都可能有其依赖项。 The modules installed in the root package.json are installed in all the subproject.安装在根package.json中的模块安装在所有子项目中。 When you run lerna bootstrap it will run npm install on each project.当您运行lerna bootstrap ,它将在每个项目上运行npm install

how i configure the lerna.json and package.json in the root folder.我如何在根文件夹中配置 lerna.json 和 package.json。

The lerna.json is quite simple and contains configuration that collects all the project lerna should manage. lerna.json非常简单,包含收集 lerna 应该管理的所有项目的配置。

The package.json is to track shared packages between all your project. package.json用于跟踪所有项目之间的共享包。 For example you could have some constant-module that must be the same version on both the projects.例如,您可能有一些constant-module ,它们在两个项目上必须是相同的版本。 In a simple fontend/backend, it is realistic to don't have any shared modules.在简单的前端/后端中,没有任何共享模块是现实的。

how can i run the application?我如何运行应用程序?

when you run lerna run start , lerna will execute npm run start on all the tracked project.当您运行lerna run start ,lerna 将对所有跟踪的项目执行npm run start So you must be aware how to start you whole application.所以你必须知道如何启动你的整个应用程序。

In my example, I implemented the start only in the backend project since it will serve statically the frontend files and I didn't want to start another webserver only for the frontend.在我的示例中,我仅在后端项目中实现了start ,因为它将静态地提供前端文件,而且我不想仅为前端启动另一个网络服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM