{"id":20381,"date":"2024-11-19T16:40:55","date_gmt":"2024-11-19T08:40:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/20381\/"},"modified":"2024-11-19T16:40:55","modified_gmt":"2024-11-19T08:40:55","slug":"%e7%8e%a9%e8%bd%aclerna%ef%bc%8c%e5%8a%a9%e4%bd%a0%e8%bd%bb%e6%9d%be%e6%90%ad%e5%bb%bamonorepo","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/20381\/","title":{"rendered":"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo"},"content":{"rendered":"<h2><strong>\u4ec0\u4e48\u662f Monorepo\uff1f&nbsp;<\/strong><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">monorepo<\/span><span style=\"vertical-align: inherit\">\u662f\u5177\u6709\u591a\u4e2a\u76f8\u5173\u670d\u52a1\u3001\u9879\u76ee\u548c\u7ec4\u4ef6\u7684\u5355\u4e2a<\/span><span style=\"vertical-align: inherit\">\u5b58\u50a8\u5e93\uff0c\u4e0d\u540c\u7684\u56e2\u961f\u53ef\u4ee5\u4f7f\u7528<\/span><\/span>\u5b83<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u6765\u5b58\u50a8\u76f8\u5173\u6216\u4e0d\u76f8\u5173\u9879\u76ee\u7684\u4ee3\u7801\u3002<\/span><span style=\"vertical-align: inherit\">monorepo \u4e00\u8bcd\u6e90\u81ea mono\uff0c\u610f\u601d\u662f\u5355\u4e2a\uff0c\u800c repo \u662f\u5b58\u50a8\u5e93\u7684\u7f29\u5199\u3002<\/span><\/span><span style=\"vertical-align: inherit\"><\/span><span style=\"vertical-align: inherit\"><\/span><\/p>\n<h2><strong>Monorepo \u7684\u597d\u5904<\/strong><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u4ee5\u4e0b\u662f\u4f7f\u7528 monorepo \u7684\u4e00\u4e9b\u4e3b\u8981\u597d\u5904\uff1a<\/span><\/p>\n<ul>\n<li> <strong>\u4ee3\u7801\u5171\u4eab\uff1a<\/strong><span style=\"vertical-align: inherit\">&nbsp; \u9879\u76ee\u5171\u4eab\u6807\u51c6\u4ee3\u7801\u3001\u5e93\u6216\u5b9e\u7528\u7a0b\u5e8f\u3002<\/span> <\/li>\n<li> <strong>\u53ef\u91cd\u7528\u6027\uff1a<\/strong><span style=\"vertical-align: inherit\">\u7ec4\u4ef6\u9700\u8981\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u91cd\u7528\u3002<\/span> <\/li>\n<li> <strong>\u66f4\u8f7b\u677e\u7684\u4ee3\u7801\u5ba1\u67e5\uff1a<\/strong><span style=\"vertical-align: inherit\">\u4ee3\u7801\u5ba1\u67e5\u5728 monorepo \u4e2d\u66f4\u52a0\u9ad8\u6548\uff0c\u56e0\u4e3a\u5ba1\u67e5\u8005\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u76f8\u5173\u9879\u76ee\u4e4b\u95f4\u7684\u66f4\u6539\u4e0a\u4e0b\u6587\uff0c\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u5e76\u66f4\u65e9\u53d1\u73b0\u6f5c\u5728\u95ee\u9898\u3002&nbsp;<\/span> <\/li>\n<li> <strong>\u7b80\u5316 CI\/CD \u6d41\u7a0b\uff1a<\/strong><span style=\"vertical-align: inherit\">\u4f7f\u7528\u5355\u4e00\u5b58\u50a8\u5e93\u540c\u65f6\u53d1\u5e03\u591a\u4e2a\u9879\u76ee\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u3002<\/span> <\/li>\n<li> <strong>\u4e00\u81f4\u7684\u4f9d\u8d56\u5173\u7cfb\u7ba1\u7406\uff1a<\/strong><span style=\"vertical-align: inherit\">\u9879\u76ee\u5171\u4eab\u76f8\u4f3c\u6216\u91cd\u53e0\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u4e14\u60a8\u5e0c\u671b\u96c6\u4e2d\u7ba1\u7406\u4f9d\u8d56\u5173\u7cfb\u3002<\/span> <\/li>\n<li> <strong>\u56e2\u961f\u534f\u4f5c\uff1a<\/strong><span style=\"vertical-align: inherit\">\u4ece\u4e8b\u76f8\u5173\u9879\u76ee\u7684\u56e2\u961f\u53ef\u4ee5\u5728\u5355\u4e00\u5b58\u50a8\u5e93\u4e2d\u66f4\u6709\u6548\u5730\u534f\u4f5c\uff0c\u5171\u4eab\u77e5\u8bc6\u3001\u89c1\u89e3\u548c\u8d44\u6e90\u3002<\/span> <\/li>\n<li> <strong>\u5fae\u670d\u52a1\u67b6\u6784\uff1a&nbsp;<\/strong><span style=\"vertical-align: inherit\">\u5728\u5904\u7406\u4e00\u7ec4\u5bc6\u5207\u76f8\u5173\u7684\u5fae\u670d\u52a1\u65f6\uff0c\u5355\u4e00\u5b58\u50a8\u5e93\u53ef\u4ee5\u7b80\u5316\u8de8\u670d\u52a1\u7684\u4ee3\u7801\u5171\u4eab\u3001\u4f9d\u8d56\u5173\u7cfb\u7ba1\u7406\u548c\u6d4b\u8bd5\u3002<\/span> <\/li>\n<li> <strong>\u7248\u672c\u4e00\u81f4\u6027\uff1a&nbsp;<\/strong><span style=\"vertical-align: inherit\">\u6240\u6709\u9879\u76ee\u90fd\u53ef\u4ee5\u5171\u4eab\u6807\u51c6\u7248\u672c\u63a7\u5236\u67b6\u6784\uff0c\u4ece\u800c\u7b80\u5316\u6c9f\u901a\u548c\u7406\u89e3\u3002<\/span> <\/li>\n<\/ul>\n<h2><span style=\"vertical-align: inherit\">\u4e13\u95e8\u8bbe\u8ba1\u7528\u4e8e\u4f7f\u7528 Node.js \u7ba1\u7406 Monorepos \u7684\u5e93\u548c\u5de5\u5177<\/span><\/h2>\n<ul>\n<li> <strong>Lerna<\/strong><span style=\"vertical-align: inherit\">\uff1a\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u5de5\u5177\uff0c\u7528\u4e8e\u7ba1\u7406\u5177\u6709\u591a\u4e2a\u5305\u7684 JavaScript \u9879\u76ee\u3002<\/span> <\/li>\n<li> <strong>Nx<\/strong><span style=\"vertical-align: inherit\">\uff1aNx \u4e13\u6ce8\u4e8e Angular \u4f46\u9002\u7528\u4e8e\u5176\u4ed6\u6846\u67b6\uff0c\u4e3a monorepos \u63d0\u4f9b\u5f3a\u5927\u7684\u5f00\u53d1\u5de5\u5177\uff0c\u5f3a\u8c03\u9ad8\u6548\u7684\u5de5\u4f5c\u6d41\u7a0b\u3001\u4ee3\u7801\u91cd\u7528\u548c\u6d4b\u8bd5\u3002<\/span> <\/li>\n<li> <strong>Yarn \u5de5\u4f5c\u533a<\/strong><span style=\"vertical-align: inherit\">\uff1aYarn \u7684\u5185\u7f6e monorepo \u529f\u80fd\u5141\u8bb8\u5728\u5355\u4e2a\u4ee3\u7801\u5e93\u4e2d\u7ba1\u7406\u591a\u4e2a\u5305\u3002<\/span> <\/li>\n<li> <strong>Rush<\/strong><span style=\"vertical-align: inherit\">\uff1a\u5fae\u8f6f\u5f00\u53d1\u7684\u53ef\u6269\u5c55\u7684 monorepo \u7ba1\u7406\u5668\uff0c\u9002\u7528\u4e8e\u5927\u578b\u4ee3\u7801\u5e93\u3002<\/span> <\/li>\n<li> <strong>Bolt<\/strong><span style=\"vertical-align: inherit\">\uff1a\u4e00\u79cd\u5355\u4e00\u5b58\u50a8\u5e93\u7ba1\u7406\u5de5\u5177\uff0c\u4e13\u6ce8\u4e8e\u6027\u80fd\uff0c\u5bf9\u4e8e\u67d0\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u6bd4 Lerna \u66f4\u5feb\u3002<\/span> <\/li>\n<li> <strong>Monorepo Manager<\/strong><span style=\"vertical-align: inherit\">\uff1a\u8be5\u5de5\u5177\u7b80\u5316\u4e86 monorepo \u7684\u521b\u5efa\u548c\u7ef4\u62a4\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7528\u6237\u53cb\u597d\u7684\u754c\u9762\u6765\u7ba1\u7406\u5305\u3001\u4f9d\u8d56\u9879\u548c\u811a\u672c\u3002<\/span> <\/li>\n<li> <strong>pnpm<\/strong><span style=\"vertical-align: inherit\">\uff1a\u4e0e Yarn \u4e00\u6837\uff0cpnpm \u8fd8\u901a\u8fc7\u5176\u5de5\u4f5c\u533a\u529f\u80fd\u652f\u6301 monorepo \u8bbe\u7f6e\uff0c\u901a\u8fc7\u5171\u4eab\u4f9d\u8d56\u9879\u51cf\u5c11\u91cd\u590d\u5e76\u63d0\u9ad8\u78c1\u76d8\u7a7a\u95f4\u5229\u7528\u7387\u3002<\/span> <\/li>\n<\/ul>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u6bcf\u4e2a\u5de5\u5177\u90fd\u63d0\u4f9b\u7279\u5b9a\u7684\u4f18\u70b9\u548c\u529f\u80fd\uff0c\u56e0\u6b64\u9009\u62e9\u53d6\u51b3\u4e8e\u60a8\u7684\u9879\u76ee\u7684\u8981\u6c42\u548c\u504f\u597d\u3002<\/span><\/p>\n<h2><strong>\u4e3a\u4ec0\u4e48\u662f<span style=\"font-family: Cambria, serif;font-size: 19px\">Lerna<\/span>\uff1f<\/strong><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\">Lerna<span style=\"vertical-align: inherit\">\u662f\u4e00\u4e2a\u8bbe\u8ba1\u7528\u4e8e\u7ba1\u7406\u5305\u542b\u591a\u4e2a npm \u5305\u7684\u5b58\u50a8\u5e93\u7684\u5de5\u5177\u3002<\/span>\u5b83\u7b80\u5316\u4e86\u5728\u5355\u4e2agit<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u5b58\u50a8\u5e93\u4e2d\u7684\u591a\u5305\u5b58\u50a8\u5e93\u4e2d\u5904\u7406\u4f9d\u8d56\u9879\u3001\u53d1\u5e03\u548c\u53d1\u5e03\u5305\u7684\u8fc7\u7a0b<\/span><span style=\"vertical-align: inherit\">\u3002<\/span><span style=\"vertical-align: inherit\">Lerna \u5bf9\u4e8e monorepo \u7279\u522b\u6709\u7528\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5728\u540c\u4e00\u5b58\u50a8\u5e93\u4e2d\u5904\u7406\u4e0d\u540c npm \u5305\u7684\u5f00\u53d1\u4eba\u5458\u4e4b\u95f4\u5b9e\u73b0\u9ad8\u6548\u7684\u4ee3\u7801\u5171\u4eab\u548c\u534f\u4f5c\u3002<\/span><span style=\"vertical-align: inherit\">\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5c06\u5177\u6709\u591a\u4e2a\u5305\u7684\u9879\u76ee\u89c6\u4e3a\u5355\u4e2a\u5b9e\u4f53\uff0c\u4ece\u800c\u6539\u8fdb\u5f00\u53d1\u751f\u547d\u5468\u671f\u7ba1\u7406\u3002<\/span><\/span><\/p>\n<h3><span style=\"vertical-align: inherit\">\u5b89\u88c5 Lerna \u4e4b\u524d\u7684\u5148\u51b3\u6761\u4ef6<\/span><\/h3>\n<ul>\n<li> <strong>Git<\/strong><span style=\"vertical-align: inherit\">\uff1a\u4e0b\u8f7d\u5e76\u5b89\u88c5Git<\/span> <\/li>\n<li> <strong>Git Bash\uff08\u7ec8\u7aef\uff09<\/strong><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\uff1a\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f Windows\uff0cGit Bash \u5305\u542b\u5728 Git \u5b89\u88c5\u4e2d\uff1b<\/span><span style=\"vertical-align: inherit\">\u5bf9\u4e8e macOS \u548c Linux\uff0c\u8bf7\u4f7f\u7528\u7cfb\u7edf\u7684\u7ec8\u7aef\u3002<\/span><\/span> <\/li>\n<li> <strong>Node.js<\/strong><span style=\"vertical-align: inherit\">\uff1a\u4e0b\u8f7d\u5e76\u5b89\u88c5<\/span>Node.js<\/li>\n<li> <strong>npm<\/strong><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\uff1anpm \u5305\u542b\u5728 Node.js \u4e2d\uff0c\u56e0\u6b64\u4e00\u65e6\u5b89\u88c5\u4e86 Node.js\uff0cnpm \u5c31\u53ef\u4ee5\u5728\u60a8\u7684\u7ec8\u7aef\u4e2d\u4f7f\u7528\u3002<\/span><span style=\"vertical-align: inherit\">\u901a\u8fc7\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u8fdb\u884c\u9a8c\u8bc1\u3002<\/span><\/span>npm -v<span style=\"vertical-align: inherit\">\u3002<\/span> <\/li>\n<\/ul>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u6211\u4eec\u6b63\u5728\u521b\u5efa\u4e00\u4e2a\u5355\u4e00\u5b58\u50a8\u5e93\uff0c\u5176\u4e2d\u5305\u62ec\u540e\u7aef\u670d\u52a1\u5668\u4f7f\u7528\u7684\u652f\u4ed8\u670d\u52a1\u3002<\/span><span style=\"vertical-align: inherit\">\u6b64\u5916\uff0c\u540e\u7aef\u670d\u52a1\u5668\u548c\u652f\u4ed8\u670d\u52a1\u5c06\u5171\u4eab\u65e5\u5fd7\u670d\u52a1\u3002<\/span><\/span><\/p>\n<ul>\n<li> <strong>\u65e5\u5fd7\u670d\u52a1\uff1a<\/strong><span style=\"background-color: transparent\">&nbsp;\u4e13\u4e3a\u8de8\u5404\u79cd\u670d\u52a1\u8fdb\u884c\u9ad8\u6548\u65e5\u5fd7\u8bb0\u5f55\u800c\u8bbe\u8ba1\u3002<\/span> <\/li>\n<li> <strong>\u652f\u4ed8\u670d\u52a1\uff1a&nbsp;<\/strong><span style=\"vertical-align: inherit\">\u8d1f\u8d23\u5904\u7406\u652f\u4ed8\u76f8\u5173\u529f\u80fd\u3002<\/span> <\/li>\n<li> <strong>\u540e\u7aef\u670d\u52a1\u5668\uff1a&nbsp;<\/strong><span style=\"vertical-align: inherit\">\u6267\u884c\u652f\u4ed8\u5904\u7406\u5e76\u96c6\u6210\u65e5\u5fd7\u670d\u52a1\u4ee5\u5b9e\u73b0\u65e0\u7f1d\u64cd\u4f5c\u3002<\/span> <\/li>\n<\/ul>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/800\/759\/365\/1694397078792054.png\" class=\"aligncenter\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe\" \/><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u73b0\u5728\u8ba9\u6211\u4eec\u6df1\u5165\u7814\u7a76\u4f7f\u7528 Lerna \u5b9e\u73b0 Monorepo\u3002<\/span><\/p>\n<h2><span style=\"vertical-align: inherit\">\u7b2c1\u6b65\uff1a\u521b\u5efa\u76ee\u5f55\u5e76\u521d\u59cb\u5316Lerna<\/span><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u5bfc\u822a\u5230\u9879\u76ee\u7684\u6839\u76ee\u5f55\u5e76\u521d\u59cb\u5316 Lerna\uff1a<\/span><\/p>\n<pre>mkdir&nbsp;monorepo&nbsp;#&nbsp;create&nbsp;a&nbsp;repo&nbsp;directory&nbsp;of&nbsp;the&nbsp;monorepo&nbsp;\ncd&nbsp;monorepo\nnpx&nbsp;lerna@latest&nbsp;init&nbsp;#&nbsp;initalize&nbsp;the&nbsp;repo<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u4e0a\u9762\u7684<\/span>npx<span style=\"vertical-align: inherit\">\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Lerna \u7ba1\u7406\u7684\u5b58\u50a8\u5e93\u3002<\/span><br \/>lerna.json<span style=\"vertical-align: inherit\">\uff1a\u914d\u7f6e\u6587\u4ef6\u5305\u542bLerna\u884c\u4e3a\u7684\u8bbe\u7f6e\uff0c\u4f8b\u5982\u7248\u672c\u63a7\u5236\u6a21\u5f0f\u3001\u5305\u4f4d\u7f6e\u7b49<\/span><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\">package.json<span style=\"vertical-align: inherit\">\uff1a\u6574\u4e2a\u5b58\u50a8\u5e93\u7684\u6839 package.json \u6587\u4ef6\u3002<\/span><\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/495\/551\/637\/1694397153311761.png\" class=\"aligncenter\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe1\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe1\" \/><\/p>\n<pre>git&nbsp;config&nbsp;user.name&nbsp;${username}\ngit&nbsp;config&nbsp;user.email&nbsp;${email}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h2><strong>\u7b2c2\u6b65\uff1a\u751f\u6210\u540e\u7aef\u5305<\/strong><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u786e\u4fdd\u60a8\u4f4d\u4e8e\u9879\u76ee\u7684\u6839\u6587\u4ef6\u5939\u4e2d\u3002&nbsp;<\/span><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u7528\u4e8e\u521b\u5efa\u5305\u7684 Lerna \u547d\u4ee4\uff1a<\/span>npx lerna create #{packageName} #{directory}<\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u8fd9\u91cc\uff0c\u76ee\u5f55\u662f\u9ed8\u8ba4\u7684\uff1a<\/span>packages<\/p>\n<pre>npx&nbsp;lerna&nbsp;create&nbsp;back-end&nbsp;\n\/\/or\n\/\/this&nbsp;will&nbsp;skip&nbsp;the&nbsp;questionnaire&nbsp;related&nbsp;to&nbsp;package\nnpx&nbsp;lerna&nbsp;create&nbsp;back-end&nbsp;-y<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><span style=\"font-family: cambria, serif;font-size: 19px;vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u4e0a\u9762\u7684\u547d\u4ee4\uff0c\u4e0d\u5e26<\/span><\/span>-y<span style=\"font-family: cambria, serif;font-size: 19px;vertical-align: inherit\"><span style=\"vertical-align: inherit\">&nbsp; \u4f1a\u63d0\u793a\u4f60\u5404\u79cd\u95ee\u9898\uff0c\u6bd4\u5982\u8986\u76d6\u5305\u540d\u3001\u6dfb\u52a0\u63cf\u8ff0\u7b49\u7b49\u3002<\/span><span style=\"vertical-align: inherit\">\u4f46\u662f\uff0c\u8fd9\u4e9b\u8be6\u7ec6\u4fe1\u606f\u5bf9\u4e8e\u672c\u793a\u4f8b\u6765\u8bf4\u5e76\u4e0d\u91cd\u8981\uff0c\u56e0\u6b64\u8bf7\u6309\u201center\u201d\u952e\u3002<\/span><\/span><\/p>\n<p><span style=\"font-family: Cambria, serif;font-size: 19px;vertical-align: inherit\"><span style=\"vertical-align: inherit\"><span style=\"font-family: Cambria, serif;font-size: 19px\">\u8fd0\u884c\u540e\uff0c\u5305\u540e\u7aef\u5c06\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/span><\/span><\/p>\n<p style=\"text-align:center\"><span style=\"font-family: Cambria, serif;font-size: 19px;vertical-align: inherit\"><span style=\"vertical-align: inherit\"><span style=\"font-family: Cambria, serif;font-size: 19px\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/860\/909\/468\/1694397255513802.png\" class=\"aligncenter\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe2\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe2\" \/><\/span><\/span><\/span><\/p>\n<p><span style=\"font-family: Cambria, serif;font-size: 19px;vertical-align: inherit\"><span style=\"vertical-align: inherit\"><span style=\"font-family: Cambria, serif;font-size: 19px\"><\/span><\/span><\/span><\/p>\n<h2><span style=\"vertical-align: inherit\">\u6b65\u9aa43\uff1a\u751f\u6210\u652f\u4ed8\u548c\u65e5\u5fd7\u670d\u52a1\u5305<\/span><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u518d\u6b21\u6267\u884c\u76f8\u540c\u7684\u8fc7\u7a0b\uff0c\u4f46\u6307\u5b9a\u8981\u521b\u5efa\u7684\u670d\u52a1\u7684\u76ee\u5f55\uff0c\u56e0\u4e3a\u6211\u4eec\u5e0c\u671b\u5305\u4f4d\u4e8e\u8be5<\/span>&#8220;services\/&#8221;<span style=\"vertical-align: inherit\">\u76ee\u5f55\u4e2d\u3002<\/span><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u5728\u6839<\/span>package.json<span style=\"vertical-align: inherit\">\u6587\u4ef6\u4e2d\uff0c\u60a8\u8fd8\u5fc5\u987b\u544a\u77e5 Lerna \u76ee\u5f55\u4e2d\u7684\u5305<\/span>services\/<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u3002<\/span><span style=\"vertical-align: inherit\">\u7f16\u8f91<\/span><\/span>package.json<span style=\"vertical-align: inherit\">\u5de5\u4f5c\u533a\u914d\u7f6e\u5e76\u6dfb\u52a0<\/span>&#8220;services\/*&#8221;<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u5230\u5176\u4e2d\u3002<\/span><span style=\"vertical-align: inherit\">\u914d\u7f6e\u5e94\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/span><\/span><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u5728\u6839\u7ea7\u522b\u7684\u4e3b<\/span>package.json<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u6587\u4ef6\u4e2d\uff0c\u60a8\u5fc5\u987b\u544a\u77e5 Lerna services\/ \u76ee\u5f55\u4e2d\u7684\u8f6f\u4ef6\u5305\u3002<\/span><span style=\"vertical-align: inherit\">\u4fee\u6539\u5de5\u4f5c\u533a\u914d\u7f6e<\/span><\/span>package.json<span style=\"vertical-align: inherit\">\u5e76\u5305\u542b<\/span>&#8220;services\/*&#8221;<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">.&nbsp;<\/span><span style=\"vertical-align: inherit\">\u914d\u7f6e\u5e94\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/span><\/p>\n<p style=\"text-align:center\"><span style=\"font-family: Cambria, serif;font-size: 19px;vertical-align: inherit\"><span style=\"vertical-align: inherit\"><span style=\"font-family: Cambria, serif;font-size: 19px\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/340\/484\/151\/1694397284623656.png\" class=\"aligncenter\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe3\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe3\" \/><\/span><\/span><\/span><\/p>\n<pre>npx&nbsp;lerna&nbsp;create&nbsp;payment&nbsp;services&nbsp;-y\nnpx&nbsp;lerna&nbsp;create&nbsp;logging&nbsp;services&nbsp;-y<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h2><span style=\"vertical-align: inherit\">\u7b2c 4 \u6b65\uff1a\u8bbe\u7f6e\u65e5\u5fd7\u670d\u52a1<\/span><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u5728\u8be5\u76ee\u5f55\u4e2d\uff0c<\/span><span style=\"vertical-align: inherit\">\u901a\u8fc7\u7b80\u5355\u7684\u914d\u7f6e\u4f7f\u7528 Bunyan \u5e93<\/span><\/span>services\/logging<span style=\"vertical-align: inherit\">\u8bbe\u7f6e<\/span>\u65e5\u5fd7\u8bb0\u5f55\u670d\u52a1\u3002<span style=\"vertical-align: inherit\"><\/span><\/p>\n<ul>\n<li>\n<p><span style=\"vertical-align: inherit\">\u5728\u65e5\u5fd7\u670d\u52a1\u4e2d\u5b89\u88c5 Buyan \u5e93\uff0c\u5e76\u5c06 Mocha \u4f5c\u4e3a\u5f00\u53d1\u4f9d\u8d56\u9879\u5b89\u88c5\u5728\u6839\u76ee\u5f55\u4e2d\uff0c\u4ee5\u6d4b\u8bd5\u6240\u6709\u670d\u52a1\u3002<\/span><\/p>\n<\/li>\n<\/ul>\n<p><span style=\"vertical-align: inherit\"><\/span><\/p>\n<p><span style=\"vertical-align: inherit\"><\/span><\/p>\n<p><span><\/span><\/p>\n<pre>\/\/&nbsp;root&nbsp;folder&nbsp;install&nbsp;test&nbsp;dependencies\nnpm&nbsp;install&nbsp;mocha&nbsp;--save-dev&nbsp;\n\/\/inside&nbsp;logging\ncd&nbsp;services\/logging\nnpm&nbsp;install&nbsp;bunyan<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li>\n<p><span style=\"vertical-align: inherit\">\u66ff\u6362\u65e5\u5fd7\u529f\u80fd\u6587\u4ef6\u7684\u5185\u5bb9<\/span>services\/logging\/lib\/logging.js<\/p>\n<\/li>\n<\/ul>\n<p><span><\/span><\/p>\n<pre>const&nbsp;bunyan&nbsp;=&nbsp;require('bunyan');\nconst&nbsp;logger&nbsp;=&nbsp;bunyan.createLogger({\n&nbsp;&nbsp;name:&nbsp;'my-logging-service',\n&nbsp;&nbsp;level:&nbsp;'info',\n});\nmodule.exports&nbsp;=&nbsp;logger;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li><span style=\"vertical-align: inherit\">\u65e5\u5fd7\u8bb0\u5f55\u6d4b\u8bd5\u7528\u4f8b\uff08\u6d4b\u8bd5\u8bb0\u5f55\u5668\uff09\uff1a<\/span><\/li>\n<li> <span style=\"vertical-align: inherit\">\u66ff\u6362\u6d4b\u8bd5\u6587\u4ef6\u7684\u5185\u5bb9<\/span>services\/logging\/__tests__\/logging.test.js<\/li>\n<\/ul>\n<p><span><\/span><\/p>\n<pre>const&nbsp;loggingService&nbsp;=&nbsp;require('..\/lib\/logging');&nbsp;\/\/&nbsp;Import&nbsp;the&nbsp;logging&nbsp;service\ndescribe('Logging&nbsp;Service',&nbsp;()&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;it('should&nbsp;log&nbsp;messages',&nbsp;()&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;loggingService.info('Test&nbsp;log&nbsp;message');\n&nbsp;&nbsp;});\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li><span style=\"vertical-align: inherit\">\u66f4\u65b0 services\/logging \u7684 package.json \u4e2d\u7684\u6d4b\u8bd5\u811a\u672c\u3002<\/span><\/li>\n<\/ul>\n<pre>\"test\":&nbsp;\"mocha&nbsp;.\/__tests__\/logging.test.js\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">package.json \u5e94\u5982\u6240\u9644\u56fe\u50cf\u6240\u793a\u3002<\/span><\/span><\/li>\n<\/ul>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/967\/189\/792\/1694397579942427.png\" class=\"aligncenter\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe4\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe4\" \/><\/p>\n<ul>\n<li> <span style=\"vertical-align: inherit\">\u662f\u65f6\u5019\u4f7f\u7528 lerna \u8fd0\u884c\u6d4b\u8bd5\u4e86<\/span>npx lerna run test &#8211;scope=&#8221;logging&#8221;<\/li>\n<\/ul>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/169439838798033.png\" style=\"max-width:90%\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe5\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe5\" \/><\/p>\n<ul>\n<li><span style=\"vertical-align: inherit\">\u65e5\u5fd7\u670d\u52a1\u5b9e\u73b0\u73b0\u5df2\u5c31\u4f4d\uff0c\u8ba9\u6211\u4eec\u5f00\u53d1\u652f\u4ed8\u670d\u52a1\u3002<\/span><\/li>\n<\/ul>\n<h2><strong>\u7b2c5\u6b65\uff1a\u8bbe\u7f6e\u652f\u4ed8\u670d\u52a1<\/strong><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u4ed8\u6b3e\u670d\u52a1\u5177\u6709\u4e00\u4e2a\u540d\u4e3a \u7684\u51fd\u6570<\/span>makePayment<span style=\"vertical-align: inherit\">\uff0c\u5b83\u63a5\u53d7\u5355\u4e2a\u53c2\u6570\u4f5c\u4e3a\u91d1\u989d\u5e76\u5229\u7528\u8bb0\u5f55\u5668\u670d\u52a1\u6765\u8bb0\u5f55\u6d3b\u52a8\u3002<\/span><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u5728<\/span>services\/payment<span style=\"vertical-align: inherit\">\u76ee\u5f55\u5185\uff0c\u5e76\u901a\u8fc7\u7b80\u5355\u7684\u529f\u80fd\u8bbe\u7f6e\u652f\u4ed8\u670d\u52a1\u3002<\/span><\/p>\n<ul>\n<li><span style=\"vertical-align: inherit\">\u5c06\u73b0\u6709\u811a\u672c\u66ff\u6362\u4e3a mocha\uff0c\u63d0\u4f9b\u7528\u4e8e\u6d4b\u8bd5\u76ee\u7684\u7684\u4ee3\u7801\u7247\u6bb5\u3002<\/span><\/li>\n<li> <span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u8981\u5728\u652f\u4ed8\u670d\u52a1\u4e2d\u4f7f\u7528\u65e5\u5fd7\u8bb0\u5f55\u670d\u52a1\uff0c\u8bf7\u5c06\u5176\u4f9d\u8d56\u9879\u6dfb\u52a0\u5230\u652f\u4ed8\u670d\u52a1\u7684 package.json \u4e2d\uff0c\u5982\u4e0b\u6240\u8ff0\u3002<\/span><span style=\"vertical-align: inherit\">\u7136\u540e\uff0c<\/span><\/span>npm i<span style=\"vertical-align: inherit\">\u5728<\/span>services\/payment<span style=\"vertical-align: inherit\">\u76ee\u5f55\u4e2d\u8fd0\u884c\u8fdb\u884c\u5b89\u88c5\u3002<\/span> <\/li>\n<\/ul>\n<pre>\"scripts\":&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\"test\":&nbsp;\"mocha&nbsp;.\/__tests__\/payment.test.js\"\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\"dependencies\":&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\"logging\":&nbsp;\"file:..\/logging\"\n&nbsp;&nbsp;}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li>package.json<span style=\"vertical-align: inherit\">\u5e94\u8be5\u5982\u56fe\u7247\u6240\u793a<\/span><span style=\"text-align: center;margin: auto;float: none !important;width: 500px\"><span>   <span style=\"margin: auto;width: 500px;float: none !important\"><span>   <img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/169439839051843.png\" style=\"max-width:90%\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe6\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe6\" \/>  <\/span><\/span>  <\/span><\/span> <\/li>\n<li>  <span style=\"vertical-align: inherit\">\u66ff\u6362\u652f\u4ed8\u6587\u4ef6\u7684\u5185\u5bb9\u3002<\/span>services\/payment\/lib\/payment.js <\/li>\n<\/ul>\n<p><span><\/span><\/p>\n<pre>const&nbsp;loggingService&nbsp;=&nbsp;require('logging');\nconst&nbsp;paymentService&nbsp;=&nbsp;{\n&nbsp;&nbsp;makePayment:&nbsp;(amount)&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;loggingService.info('Payment&nbsp;processing&nbsp;initiated');\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Implement&nbsp;payment&nbsp;logic&nbsp;here\n&nbsp;&nbsp;&nbsp;&nbsp;loggingService.info('Payment&nbsp;processed&nbsp;successfully');\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;`Payment&nbsp;of&nbsp;${amount}&nbsp;processed&nbsp;successfully`;\n&nbsp;&nbsp;},\n};\nmodule.exports&nbsp;=&nbsp;paymentService;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li>makePayment<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u652f\u4ed8\u670d\u52a1\u529f\u80fd<\/span><span style=\"vertical-align: inherit\">\u6d4b\u8bd5\u7528\u4f8b\u3002<\/span><\/span> <\/li>\n<li> <span style=\"vertical-align: inherit\">\u66ff\u6362\u6d4b\u8bd5\u6587\u4ef6\u7684\u5185\u5bb9<\/span>services\/payment\/__tests__\/payment.test.js<\/li>\n<\/ul>\n<p><span><\/span><\/p>\n<pre>const&nbsp;chai&nbsp;=&nbsp;require('chai');\nconst&nbsp;paymentService&nbsp;=&nbsp;require('..\/lib\/payment');&nbsp;\/\/&nbsp;Import&nbsp;the&nbsp;payment&nbsp;service\nconst&nbsp;expect&nbsp;=&nbsp;chai.expect;\ndescribe('Payment&nbsp;Service',&nbsp;()&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;it('should&nbsp;make&nbsp;a&nbsp;payment&nbsp;successfully',&nbsp;()&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;paymentResult&nbsp;=&nbsp;paymentService.makePayment(100);\n&nbsp;&nbsp;&nbsp;&nbsp;expect(paymentResult).to.equal('Payment&nbsp;of&nbsp;100&nbsp;processed&nbsp;successfully');\n&nbsp;&nbsp;});\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li> <span style=\"vertical-align: inherit\">\u662f\u65f6\u5019\u4f7f\u7528 lerna \u8fd0\u884c\u6d4b\u8bd5\u4e86<\/span>npx lerna run test &#8211;scope=&#8221;payment&#8221;<img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/169439839334235.png\" style=\"max-width:90%\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe7\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe7\" \/> <\/li>\n<li><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u652f\u4ed8\u670d\u52a1\u7684\u5b9e\u65bd\u3002<\/span><span style=\"vertical-align: inherit\">\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u7ee7\u7eed\u521b\u5efa\u540e\u7aef\u670d\u52a1\u3002<\/span><\/span><\/li>\n<\/ul>\n<h2><strong>\u7b2c 6 \u6b65\uff1a\u8bbe\u7f6e\u540e\u7aef\u670d\u52a1\u5668<\/strong><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u6211\u4eec\u5c06\u4f7f\u7528\u57fa\u672c\u7684 GET API \u914d\u7f6e\u670d\u52a1\u5668\uff0c\u8be5 API \u5229\u7528\u8bb0\u5f55\u5668\u548c\u652f\u4ed8\u670d\u52a1\u3002<\/span><span style=\"vertical-align: inherit\">\u6b64\u8bbe\u7f6e\u5c06\u6709\u52a9\u4e8e\u4ed8\u6b3e\u548c\u8bb0\u5f55\u76f8\u5e94\u7684\u6d3b\u52a8\u3002<\/span><\/span><\/p>\n<ul>\n<li><span style=\"vertical-align: inherit\">\u5b89\u88c5 Express \u670d\u52a1\u5668\u5e76\u5b9e\u73b0\u4f7f\u7528\u8fd9\u4e24\u79cd\u670d\u52a1\u7684\u529f\u80fd\u3002<\/span><\/li>\n<\/ul>\n<pre>\/\/from&nbsp;root\ncd&nbsp;packages\/back-end\nnpm&nbsp;install&nbsp;express<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li> <span style=\"vertical-align: inherit\">\u66ff\u6362\u65e5\u5fd7\u529f\u80fd\u6587\u4ef6\u7684\u5185\u5bb9<\/span>packages\/back-end\/lib\/back-end.js<\/li>\n<li> <span style=\"vertical-align: inherit\">\u6211\u4eec\u60f3\u5728\u670d\u52a1\u5668\u4e2d\u4f7f\u7528\u652f\u4ed8\u548c\u65e5\u5fd7\u670d\u52a1\uff0c\u6240\u4ee5\u8ba9\u6211\u4eec\u5728<\/span>package.json<span style=\"vertical-align: inherit\">of\u7684\u4f9d\u8d56\u9879\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5<\/span>packages\/back-end&nbsp;<\/li>\n<\/ul>\n<pre>\"logging\":&nbsp;\"file:..\/services\/logging\",\n\"payment\":&nbsp;\"file:..\/services\/payment\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li><span style=\"vertical-align: inherit\">\u66ff\u6362\u811a\u672c\u5757\u6765\u8fd0\u884c\u670d\u52a1\u5668\u5e76\u8fdb\u884c\u6d4b\u8bd5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/li>\n<\/ul>\n<pre>\"scripts\":&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\"start\":&nbsp;\"node&nbsp;.\/lib\/back-end.js\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"test\":&nbsp;\"mocha&nbsp;.\/__tests__\/back-end.test.js&nbsp;--exit\"\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li>package.json<span style=\"vertical-align: inherit\">\u5e94\u8be5\u5982\u6240\u9644\u56fe\u7247\u6240\u793a<\/span> <\/li>\n<\/ul>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/169439839635437.png\" style=\"max-width:90%\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe8\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe8\" \/><\/p>\n<ul>\n<li> <span style=\"vertical-align: inherit\">\u73b0\u5728\uff0c\u901a\u8fc7\u6267\u884c\u66f4\u65b0\u4f9d\u8d56\u9879<\/span>npm update<span style=\"vertical-align: inherit\">\u3002<\/span> <\/li>\n<li> <span style=\"vertical-align: inherit\">\u5c06 \u7684\u5185\u5bb9\u66ff\u6362<\/span>packages\/back-end\/lib\/back-end.js<span style=\"vertical-align: inherit\">\u4e3a\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/span>\n<ul>\n<li> <span style=\"vertical-align: inherit\">\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u5e26\u6709<\/span>get \/ API<span style=\"vertical-align: inherit\">\u7aef\u53e3\u7684\u670d\u52a1\u5668<\/span>3000<span style=\"vertical-align: inherit\">\uff0c\u5e76\u4f7f\u7528\u65e5\u5fd7\u8bb0\u5f55\u548c\u652f\u4ed8\u670d\u52a1\u3002&nbsp;<\/span> <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><span><\/span><\/p>\n<pre>const&nbsp;express&nbsp;=&nbsp;require('express');\nconst&nbsp;loggingService&nbsp;=&nbsp;require('logging');\nconst&nbsp;paymentService&nbsp;=&nbsp;require('payment');\nconst&nbsp;app&nbsp;=&nbsp;express();\napp.get('\/',&nbsp;(req,&nbsp;res)&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;\/\/&nbsp;Use&nbsp;of&nbsp;logging&nbsp;service\n&nbsp;&nbsp;loggingService.info('Backend&nbsp;server&nbsp;received&nbsp;a&nbsp;request');\n&nbsp;&nbsp;\n&nbsp;&nbsp;\/\/&nbsp;Use&nbsp;the&nbsp;payment&nbsp;service\n&nbsp;&nbsp;const&nbsp;paymentResult&nbsp;=&nbsp;paymentService.makePayment(100);\n&nbsp;&nbsp;loggingService.info('Payment&nbsp;result:',&nbsp;paymentResult);\n&nbsp;&nbsp;res.send('Backend&nbsp;Server:&nbsp;Running!');\n});\napp.listen(3000,&nbsp;()&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;console.log('Backend&nbsp;server&nbsp;is&nbsp;running&nbsp;on&nbsp;port&nbsp;3000');\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li> <span style=\"vertical-align: inherit\">\u5b89\u88c5<\/span>chai-http<span style=\"vertical-align: inherit\">\u4ee5\u5bf9\u76ee\u5f55\u4e0a\u7684 API \u8fdb\u884c\u5355\u5143\u6d4b\u8bd5<\/span>packages\/back-end<span style=\"vertical-align: inherit\">\u3002<\/span>\n<ul>\n<li>&nbsp;npm i chai-http &#8211;save-dev&nbsp;<\/li>\n<\/ul>\n<\/li>\n<li><span style=\"vertical-align: inherit\">\u66ff\u6362\u6d4b\u8bd5\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u6211\u4eec\u5c06\u5728\u5176\u4e2d\u6d4b\u8bd5 API \u662f\u5426\u6309\u9884\u671f\u5de5\u4f5c\u3002<\/span><\/li>\n<\/ul>\n<p><span><\/span><\/p>\n<p><span><\/span><\/p>\n<pre>const&nbsp;chai&nbsp;=&nbsp;require('chai');\nconst&nbsp;chaiHttp&nbsp;=&nbsp;require('chai-http');\nconst&nbsp;app&nbsp;=&nbsp;require('..\/lib\/back-end');&nbsp;\/\/&nbsp;Import&nbsp;the&nbsp;Express&nbsp;app\n\/\/&nbsp;using&nbsp;request&nbsp;server&nbsp;as&nbsp;chaiHttp;\nchai.use(chaiHttp);\nconst&nbsp;expect&nbsp;=&nbsp;chai.expect;\ndescribe('Backend&nbsp;Server',&nbsp;()&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;it('should&nbsp;log&nbsp;a&nbsp;request&nbsp;and&nbsp;process&nbsp;payment',&nbsp;(done)&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;chai.request(app)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.get('\/')\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.end((err,&nbsp;res)&nbsp;=&amp;gt;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect(res).to.have.status(200);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect(res.text).to.equal('Backend&nbsp;Server:&nbsp;Running!');\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;done();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});\n&nbsp;&nbsp;});\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u606d\u559c\uff01<\/span><span style=\"vertical-align: inherit\">\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86 monorepo \u4e2d\u4e09\u4e2a\u5fae\u670d\u52a1\u7684\u7b80\u6d01\u6709\u6548\u7684\u5b9e\u73b0\u3002&nbsp;<\/span><\/span><\/li>\n<\/ul>\n<h2><strong>\u7b2c 7 \u6b65\uff1a\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f<\/strong><\/h2>\n<ul>\n<li><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u4f1f\u5927\u7684\uff01<\/span><span style=\"vertical-align: inherit\">\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u542f\u52a8\u670d\u52a1\u5668\u5e76\u89c2\u5bdf\u6240\u6709\u670d\u52a1\u5982\u4f55\u7ec4\u5408\u5728\u4e00\u8d77\u5e76\u5de5\u4f5c\u3002<\/span><\/span><\/li>\n<li> <span style=\"vertical-align: inherit\"><\/span>lerna run start<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u5728\u6839\u6587\u4ef6\u5939\u4e2d<\/span><span style=\"vertical-align: inherit\">\u6267\u884c\u3002<\/span><span style=\"vertical-align: inherit\">\u8fd9\u5c06\u5728\u7aef\u53e3 3000 \u4e0a\u542f\u52a8\u670d\u52a1\u5668\u3002\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u5bfc\u822a\u81f3<\/span><\/span>localhost:3000\/<span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u3002<\/span><span style=\"vertical-align: inherit\">\u60a8\u5c06\u89c2\u5bdf\u5230\u8f93\u51fa<\/span><\/span><strong>\u201c\u540e\u7aef\u670d\u52a1\u5668\uff1a\u6b63\u5728\u8fd0\u884c\uff01\u201d&nbsp;<\/strong><span style=\"vertical-align: inherit\">\u663e\u793a\u5728\u6d4f\u89c8\u5668\u4e2d\u3002<\/span> <\/li>\n<li><span style=\"vertical-align: inherit\">\u68c0\u67e5\u7ec8\u7aef\u4e2d\u7684\u65e5\u5fd7\uff0c\u60a8\u5c06\u9047\u5230\u7c7b\u4f3c\u4e8e\u56fe\u4e2d\u6240\u793a\u7684\u7ed3\u679c\u3002<\/span><\/li>\n<\/ul>\n<p><span><\/span><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/169439839869259.png\" style=\"max-width:90%\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe9\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe9\" \/><\/p>\n<ul>\n<li> <span style=\"vertical-align: inherit\">\u6267\u884c<\/span>lerna run test<span style=\"vertical-align: inherit\">\uff0c\u8fd9\u5c06\u8fd0\u884c\u6240\u6709\u5fae\u670d\u52a1\u4e2d\u7684\u6240\u6709\u6d4b\u8bd5\uff0c\u56e0\u4e3a\u6240\u6709\u5fae\u670d\u52a1<\/span>test<span style=\"vertical-align: inherit\">\u5728\u811a\u672c\u4e2d\u90fd\u6709\u547d\u4ee4\u3002<\/span> <\/li>\n<\/ul>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/169439840126681.png\" style=\"max-width:90%\" title=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe10\" alt=\"\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u63d2\u56fe10\" \/><\/p>\n<h2><strong>\u7ed3\u8bba<\/strong><\/h2>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u521b\u5efa\u5177\u6709\u540e\u7aef\u670d\u52a1\u5668\u3001\u652f\u4ed8\u670d\u52a1\u548c\u65e5\u5fd7\u8bb0\u5f55\u670d\u52a1\u7684 monorepo \u51f8\u663e\u4e86\u7edf\u4e00\u5f00\u53d1\u65b9\u6cd5\u7684\u597d\u5904\u3002<\/span><span style=\"vertical-align: inherit\">\u6b64\u8bbe\u7f6e\u901a\u8fc7\u5c06\u76f8\u5173\u7ec4\u4ef6\u6574\u5408\u5230\u5355\u4e2a\u5b58\u50a8\u5e93\u4e2d\u6765\u4fc3\u8fdb\u9ad8\u6548\u7684\u4ee3\u7801\u7ba1\u7406\u548c\u5171\u4eab\u3002<\/span><\/span><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\">\u5c06\u65e5\u5fd7\u8bb0\u5f55\u670d\u52a1\u96c6\u6210\u5230\u652f\u4ed8\u670d\u52a1\u548c\u540e\u7aef\u670d\u52a1\u5668\u4e2d\u4f53\u73b0\u4e86\u4ee3\u7801\u53ef\u91cd\u7528\u6027\u548c\u8de8\u670d\u52a1\u7684\u4e00\u81f4\u65e5\u5fd7\u8bb0\u5f55\u5b9e\u8df5\u7684\u5f3a\u5927\u529f\u80fd\u3002<\/span><\/p>\n<p style=\"margin-top: 5px;margin-bottom: 15px;padding-top: 0px;font-family: Cambria, serif;font-size: 19px\"><span style=\"vertical-align: inherit\"><span style=\"vertical-align: inherit\">\u91c7\u7528 monorepo \u67b6\u6784\u4f1a\u5e26\u6765\u4e00\u4e2a\u6709\u7ec4\u7ec7\u4e14\u534f\u4f5c\u7684\u5f00\u53d1\u73af\u5883\u3002<\/span><span style=\"vertical-align: inherit\">\u6a21\u5757\u5316\u7b80\u5316\u4e86\u5f00\u53d1\uff0c\u63d0\u9ad8\u4e86\u6548\u7387\u548c\u957f\u671f\u7ef4\u62a4\u3002<\/span><span style=\"vertical-align: inherit\">\u5b83\u4e3a\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u575a\u5b9e\u7684\u57fa\u7840\uff0c\u5177\u6709\u900f\u660e\u7684\u901a\u4fe1\u3001\u4ee3\u7801\u53ef\u91cd\u7528\u6027\u548c\u6709\u6548\u7684\u6d4b\u8bd5\u3002<\/span><\/span><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u73a9\u8f6cLerna\uff0c\u52a9\u4f60\u8f7b\u677e\u642d\u5efaMonorepo\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f Monorepo\uff1f&nbsp; monorepo\u662f\u5177\u6709\u591a\u4e2a\u76f8\u5173\u670d\u52a1\u3001\u9879\u76ee\u548c\u7ec4\u4ef6\u7684\u5355\u4e2a\u5b58\u50a8\u5e93\uff0c\u4e0d\u540c\u7684\u56e2\u961f\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5b58\u50a8\u76f8\u5173\u6216\u4e0d\u76f8\u5173\u9879\u76ee\u7684\u4ee3\u7801\u3002monorepo \u4e00\u8bcd\u6e90\u81ea mono\uff0c\u610f\u601d\u662f\u5355\u4e2a\uff0c\u800c repo \u662f\u5b58\u50a8\u5e93\u7684\u7f29\u5199\u3002 Monorepo \u7684\u597d\u5904 \u4ee5\u4e0b\u662f\u4f7f\u7528 monorepo \u7684\u4e00\u4e9b\u4e3b\u8981\u597d\u5904\uff1a \u4ee3\u7801\u5171\u4eab\uff1a&nbsp; \u9879\u76ee\u5171\u4eab\u6807\u51c6\u4ee3\u7801\u3001\u5e93\u6216\u5b9e\u7528\u7a0b\u5e8f\u3002 \u53ef\u91cd\u7528\u6027\uff1a\u7ec4\u4ef6\u9700\u8981\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u91cd\u7528\u3002 \u66f4\u8f7b\u677e\u7684\u4ee3\u7801\u5ba1\u67e5\uff1a\u4ee3\u7801\u5ba1\u67e5\u5728 monorepo \u4e2d\u66f4\u52a0\u9ad8\u6548\uff0c\u56e0\u4e3a\u5ba1\u67e5\u8005\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u76f8\u5173\u9879\u76ee\u4e4b\u95f4\u7684\u66f4\u6539\u4e0a\u4e0b\u6587\uff0c\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u5e76\u66f4\u65e9\u53d1\u73b0\u6f5c\u5728\u95ee\u9898\u3002&nbsp; \u7b80\u5316 CI\/CD \u6d41\u7a0b\uff1a\u4f7f\u7528\u5355\u4e00\u5b58\u50a8\u5e93\u540c\u65f6\u53d1\u5e03\u591a\u4e2a\u9879\u76ee\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u3002 \u4e00\u81f4\u7684\u4f9d\u8d56\u5173\u7cfb\u7ba1\u7406\uff1a\u9879\u76ee\u5171\u4eab\u76f8\u4f3c\u6216\u91cd\u53e0\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u4e14\u60a8\u5e0c\u671b\u96c6\u4e2d\u7ba1\u7406\u4f9d\u8d56\u5173\u7cfb\u3002 \u56e2\u961f\u534f\u4f5c\uff1a\u4ece\u4e8b\u76f8\u5173\u9879\u76ee\u7684\u56e2\u961f\u53ef\u4ee5\u5728\u5355\u4e00\u5b58\u50a8\u5e93\u4e2d\u66f4\u6709\u6548\u5730\u534f\u4f5c\uff0c\u5171\u4eab\u77e5\u8bc6\u3001\u89c1\u89e3\u548c\u8d44\u6e90\u3002 \u5fae\u670d\u52a1\u67b6\u6784\uff1a&nbsp;\u5728\u5904\u7406\u4e00\u7ec4\u5bc6\u5207\u76f8\u5173\u7684\u5fae\u670d\u52a1\u65f6\uff0c\u5355\u4e00\u5b58\u50a8\u5e93\u53ef\u4ee5\u7b80\u5316\u8de8\u670d\u52a1\u7684\u4ee3\u7801\u5171\u4eab\u3001\u4f9d\u8d56\u5173\u7cfb\u7ba1\u7406\u548c\u6d4b\u8bd5\u3002 \u7248\u672c\u4e00\u81f4\u6027\uff1a&nbsp;\u6240\u6709\u9879\u76ee\u90fd\u53ef\u4ee5\u5171\u4eab\u6807\u51c6\u7248\u672c\u63a7\u5236\u67b6\u6784\uff0c\u4ece\u800c\u7b80\u5316\u6c9f\u901a\u548c\u7406\u89e3\u3002 \u4e13\u95e8\u8bbe\u8ba1\u7528\u4e8e\u4f7f\u7528 Node.js \u7ba1\u7406 Monorepos \u7684\u5e93\u548c\u5de5\u5177 Lerna\uff1a\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u5de5\u5177\uff0c\u7528\u4e8e\u7ba1\u7406\u5177\u6709\u591a\u4e2a\u5305\u7684 JavaScript \u9879\u76ee\u3002 Nx\uff1aNx \u4e13\u6ce8\u4e8e Angular \u4f46\u9002\u7528\u4e8e\u5176\u4ed6\u6846\u67b6\uff0c\u4e3a monorepos \u63d0\u4f9b\u5f3a\u5927\u7684\u5f00\u53d1\u5de5\u5177\uff0c\u5f3a\u8c03\u9ad8\u6548\u7684\u5de5\u4f5c\u6d41\u7a0b\u3001\u4ee3\u7801\u91cd\u7528\u548c\u6d4b\u8bd5\u3002 Yarn \u5de5\u4f5c\u533a\uff1aYarn \u7684\u5185\u7f6e monorepo \u529f\u80fd\u5141\u8bb8\u5728\u5355\u4e2a\u4ee3\u7801\u5e93\u4e2d\u7ba1\u7406\u591a\u4e2a\u5305\u3002 Rush\uff1a\u5fae\u8f6f\u5f00\u53d1\u7684\u53ef\u6269\u5c55\u7684 monorepo \u7ba1\u7406\u5668\uff0c\u9002\u7528\u4e8e\u5927\u578b\u4ee3\u7801\u5e93\u3002 Bolt\uff1a\u4e00\u79cd\u5355\u4e00\u5b58\u50a8\u5e93\u7ba1\u7406\u5de5\u5177\uff0c\u4e13\u6ce8\u4e8e\u6027\u80fd\uff0c\u5bf9\u4e8e\u67d0\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u6bd4 Lerna \u66f4\u5feb\u3002 Monorepo Manager\uff1a\u8be5\u5de5\u5177\u7b80\u5316\u4e86 monorepo \u7684\u521b\u5efa\u548c\u7ef4\u62a4\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7528\u6237\u53cb\u597d\u7684\u754c\u9762\u6765\u7ba1\u7406\u5305\u3001\u4f9d\u8d56\u9879\u548c\u811a\u672c\u3002 pnpm\uff1a\u4e0e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-20381","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/20381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=20381"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/20381\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=20381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=20381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=20381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}