{"id":4148,"date":"2021-11-30T13:23:59","date_gmt":"2021-11-30T05:23:59","guid":{"rendered":"http:\/\/123.57.164.21\/?p=4148"},"modified":"2021-11-30T13:25:59","modified_gmt":"2021-11-30T05:25:59","slug":"npm%e5%92%8cyarn%e7%9a%84%e5%8c%ba%e5%88%ab%ef%bc%8c%e6%88%91%e4%bb%ac%e8%af%a5%e5%a6%82%e4%bd%95%e9%80%89%e6%8b%a9","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=4148","title":{"rendered":"npm\u548cyarn\u7684\u533a\u522b\uff0c\u6211\u4eec\u8be5\u5982\u4f55\u9009\u62e9?"},"content":{"rendered":"\n<p>\u5047\u5982\u6211\u4eec\u8981\u8fd0\u884c\u4e00\u4e0b\u57fa\u4e8eReact\u7684\u65b0\u9879\u76ee\u3002<br>\u6309\u7167\u4ee5\u5f80\uff0cnpm\u7684\u6b65\u9aa4\u90fd\u662f\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git clone xxx\nnpm install\nnpm run dev<\/pre>\n\n\n\n<p>\u8fd9\u65f6\uff0c\u6765\u4e86\u4e0b\u9762\u4e00\u6bb5<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git clone xxx\nyarn\nyarn start<\/pre>\n\n\n\n<p>\u201c\u54a6\uff0cyarn\u662f\u4ec0\u4e48\u9b3c\uff1f\u96be\u9053npm\u66f4\u9ad8\u7ea7\u7684\u66ff\u4ee3\u54c1\uff1f\u4e3a\u4ec0\u4e48\u8981\u66ff\u4ee3npm\uff1f\u96be\u9053\u6709\u4ec0\u4e48\u597d\u7684\u5730\u65b9\uff1f\u201d\uff0c\u5185\u5fc3\u4e00\u8fde\u4e32\u7684\u95ee\u9898\u5192\u51fa\u6765\u3002\u201cyarn\u662f\u8ddfnpm\u4e00\u6837\u7684\u4e1c\u897f\u5417\uff1f\u201d<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Yarn\u662f\u4ec0\u4e48\uff1f<\/h5>\n\n\n\n<p>\u201cYarn\u662f\u7531Facebook\u3001Google\u3001Exponent \u548c Tilde \u8054\u5408\u63a8\u51fa\u4e86\u4e00\u4e2a\u65b0\u7684 JS \u5305\u7ba1\u7406\u5de5\u5177 \uff0c\u6b63\u5982<a href=\"https:\/\/link.jianshu.com?t=http%3A%2F%2Flink.zhihu.com%2F%3Ftarget%3Dhttps%253A%2F%2Fcode.facebook.com%2Fposts%2F1840075619545360\" target=\"_blank\" rel=\"noreferrer noopener\">\u5b98\u65b9\u6587\u6863<\/a>\u4e2d\u5199\u7684\uff0cYarn \u662f\u4e3a\u4e86\u5f25\u8865 npm \u7684\u4e00\u4e9b\u7f3a\u9677\u800c\u51fa\u73b0\u7684\u3002\u201d\u8fd9\u53e5\u8bdd\u8ba9\u6211\u60f3\u8d77\u4e86\u4f7f\u7528npm\u65f6\u7684\u5751\u4e86\uff1a<\/p>\n\n\n\n<ul><li><code>npm install<\/code>\u7684\u65f6\u5019<strong>\u5de8\u6162<\/strong>\u3002\u7279\u522b\u662f\u65b0\u7684\u9879\u76ee\u62c9\u4e0b\u6765\u8981\u7b49\u534a\u5929\uff0c\u5220\u9664node_modules\uff0c\u91cd\u65b0install\u7684\u65f6\u5019\u4f9d\u65e7\u5982\u6b64\u3002<\/li><li>\u540c\u4e00\u4e2a\u9879\u76ee\uff0c\u5b89\u88c5\u7684\u65f6\u5019<strong>\u65e0\u6cd5\u4fdd\u6301\u4e00\u81f4\u6027<\/strong>\u3002\u7531\u4e8epackage.json\u6587\u4ef6\u4e2d\u7248\u672c\u53f7\u7684\u7279\u70b9\uff0c\u4e0b\u9762\u4e09\u4e2a\u7248\u672c\u53f7\u5728\u5b89\u88c5\u7684\u65f6\u5019\u4ee3\u8868\u4e0d\u540c\u7684\u542b\u4e49\u3002<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"5.0.3\",\n\"~5.0.3\",\n\"^5.0.3\"<\/pre>\n\n\n\n<p><br>\u201c5.0.3\u201d\u8868\u793a\u5b89\u88c5\u6307\u5b9a\u76845.0.3\u7248\u672c\uff0c\u201c\uff5e5.0.3\u201d\u8868\u793a\u5b89\u88c55.0.X\u4e2d\u6700\u65b0\u7684\u7248\u672c\uff0c\u201c^5.0.3\u201d\u8868\u793a\u5b89\u88c55.X.X\u4e2d\u6700\u65b0\u7684\u7248\u672c\u3002\u8fd9\u5c31\u9ebb\u70e6\u4e86\uff0c\u5e38\u5e38\u4f1a\u51fa\u73b0\u540c\u4e00\u4e2a\u9879\u76ee\uff0c\u6709\u7684\u540c\u4e8b\u662fOK\u7684\uff0c\u6709\u7684\u540c\u4e8b\u4f1a\u7531\u4e8e\u5b89\u88c5\u7684\u7248\u672c\u4e0d\u4e00\u81f4\u51fa\u73b0bug\u3002<\/p>\n\n\n\n<ul><li>\u5b89\u88c5\u7684\u65f6\u5019\uff0c\u5305\u4f1a\u5728\u540c\u4e00\u65f6\u95f4\u4e0b\u8f7d\u548c\u5b89\u88c5\uff0c\u4e2d\u9014\u67d0\u4e2a\u65f6\u5019\uff0c\u4e00\u4e2a\u5305\u629b\u51fa\u4e86\u4e00\u4e2a\u9519\u8bef\uff0c\u4f46\u662fnpm\u4f1a\u7ee7\u7eed\u4e0b\u8f7d\u548c\u5b89\u88c5\u5305\u3002\u56e0\u4e3anpm\u4f1a\u628a\u6240\u6709\u7684\u65e5\u5fd7\u8f93\u51fa\u5230\u7ec8\u7aef\uff0c\u6709\u5173\u9519\u8bef\u5305\u7684\u9519\u8bef\u4fe1\u606f\u5c31\u4f1a\u5728\u4e00\u5927\u5806npm\u6253\u5370\u7684\u8b66\u544a\u4e2d\u4e22\u5931\u6389\uff0c\u5e76\u4e14\u4f60\u751a\u81f3\u6c38\u8fdc<strong>\u4e0d\u4f1a\u6ce8\u610f\u5230\u5b9e\u9645\u53d1\u751f\u7684\u9519\u8bef<\/strong>\u3002<\/li><\/ul>\n\n\n\n<p>\u5e26\u7740\u8fd9\u4e9b\u5751\uff0c\u6211\u5f00\u59cb\u4e86\u89e3Yarn\u7684\u4f18\u52bf\u53ca\u5176\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Yarn\u7684\u4f18\u70b9\uff1f<\/h5>\n\n\n\n<ul><li><strong>\u901f\u5ea6\u5feb<\/strong> \u3002\u901f\u5ea6\u5feb\u4e3b\u8981\u6765\u81ea\u4ee5\u4e0b\u4e24\u4e2a\u65b9\u9762\uff1a<\/li><\/ul>\n\n\n\n<ol><li>\u5e76\u884c\u5b89\u88c5\uff1a\u65e0\u8bba npm \u8fd8\u662f Yarn \u5728\u6267\u884c\u5305\u7684\u5b89\u88c5\u65f6\uff0c\u90fd\u4f1a\u6267\u884c\u4e00\u7cfb\u5217\u4efb\u52a1\u3002npm \u662f\u6309\u7167\u961f\u5217\u6267\u884c\u6bcf\u4e2a package\uff0c\u4e5f\u5c31\u662f\u8bf4\u5fc5\u987b\u8981\u7b49\u5230\u5f53\u524d package \u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\uff0c\u624d\u80fd\u7ee7\u7eed\u540e\u9762\u7684\u5b89\u88c5\u3002\u800c Yarn \u662f\u540c\u6b65\u6267\u884c\u6240\u6709\u4efb\u52a1\uff0c\u63d0\u9ad8\u4e86\u6027\u80fd\u3002<\/li><li>\u79bb\u7ebf\u6a21\u5f0f\uff1a\u5982\u679c\u4e4b\u524d\u5df2\u7ecf\u5b89\u88c5\u8fc7\u4e00\u4e2a\u8f6f\u4ef6\u5305\uff0c\u7528Yarn\u518d\u6b21\u5b89\u88c5\u65f6\u4e4b\u95f4\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\uff0c\u5c31\u4e0d\u7528\u50cfnpm\u90a3\u6837\u518d\u4ece\u7f51\u7edc\u4e0b\u8f7d\u4e86\u3002<\/li><\/ol>\n\n\n\n<ul><li>\u5b89\u88c5<strong>\u7248\u672c\u7edf\u4e00<\/strong>\uff1a\u4e3a\u4e86\u9632\u6b62\u62c9\u53d6\u5230\u4e0d\u540c\u7684\u7248\u672c\uff0cYarn \u6709\u4e00\u4e2a\u9501\u5b9a\u6587\u4ef6 (lock file) \u8bb0\u5f55\u4e86\u88ab\u786e\u5207\u5b89\u88c5\u4e0a\u7684\u6a21\u5757\u7684\u7248\u672c\u53f7\u3002\u6bcf\u6b21\u53ea\u8981\u65b0\u589e\u4e86\u4e00\u4e2a\u6a21\u5757\uff0cYarn \u5c31\u4f1a\u521b\u5efa\uff08\u6216\u66f4\u65b0\uff09yarn.lock \u8fd9\u4e2a\u6587\u4ef6\u3002\u8fd9\u4e48\u505a\u5c31\u4fdd\u8bc1\u4e86\uff0c\u6bcf\u4e00\u6b21\u62c9\u53d6\u540c\u4e00\u4e2a\u9879\u76ee\u4f9d\u8d56\u65f6\uff0c\u4f7f\u7528\u7684\u90fd\u662f\u4e00\u6837\u7684\u6a21\u5757\u7248\u672c\u3002npm \u5176\u5b9e\u4e5f\u6709\u529e\u6cd5\u5b9e\u73b0\u5904\u5904\u4f7f\u7528\u76f8\u540c\u7248\u672c\u7684 packages\uff0c\u4f46\u9700\u8981\u5f00\u53d1\u8005\u6267\u884c npm shrinkwrap \u547d\u4ee4\u3002\u8fd9\u4e2a\u547d\u4ee4\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a\u9501\u5b9a\u6587\u4ef6\uff0c\u5728\u6267\u884c npm install \u7684\u65f6\u5019\uff0c\u8be5\u9501\u5b9a\u6587\u4ef6\u4f1a\u5148\u88ab\u8bfb\u53d6\uff0c\u548c Yarn \u8bfb\u53d6 yarn.lock \u6587\u4ef6\u4e00\u4e2a\u9053\u7406\u3002npm \u548c Yarn \u4e24\u8005\u7684\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0cYarn \u9ed8\u8ba4\u4f1a\u751f\u6210\u8fd9\u6837\u7684\u9501\u5b9a\u6587\u4ef6\uff0c\u800c npm \u8981\u901a\u8fc7 shrinkwrap \u547d\u4ee4\u751f\u6210 npm-shrinkwrap.json \u6587\u4ef6\uff0c\u53ea\u6709\u5f53\u8fd9\u4e2a\u6587\u4ef6\u5b58\u5728\u7684\u65f6\u5019\uff0cpackages \u7248\u672c\u4fe1\u606f\u624d\u4f1a\u88ab\u8bb0\u5f55\u548c\u66f4\u65b0\u3002<\/li><li><strong>\u66f4\u7b80\u6d01\u7684\u8f93\u51fa<\/strong>\uff1anpm \u7684\u8f93\u51fa\u4fe1\u606f\u6bd4\u8f83\u5197\u957f\u3002\u5728\u6267\u884c npm install &lt;package> \u7684\u65f6\u5019\uff0c\u547d\u4ee4\u884c\u91cc\u4f1a\u4e0d\u65ad\u5730\u6253\u5370\u51fa\u6240\u6709\u88ab\u5b89\u88c5\u4e0a\u7684\u4f9d\u8d56\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0cYarn \u7b80\u6d01\u592a\u591a\uff1a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7ed3\u5408\u4e86 emoji\u76f4\u89c2\u4e14\u76f4\u63a5\u5730\u6253\u5370\u51fa\u5fc5\u8981\u7684\u4fe1\u606f\uff0c\u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e9b\u547d\u4ee4\u4f9b\u5f00\u53d1\u8005\u67e5\u8be2\u989d\u5916\u7684\u5b89\u88c5\u4fe1\u606f\u3002<\/li><li><strong>\u591a\u6ce8\u518c\u6765\u6e90\u5904\u7406\uff1a<\/strong>\u6240\u6709\u7684\u4f9d\u8d56\u5305\uff0c\u4e0d\u7ba1\u4ed6\u88ab\u4e0d\u540c\u7684\u5e93\u95f4\u63a5\u5173\u8054\u5f15\u7528\u591a\u5c11\u6b21\uff0c\u5b89\u88c5\u8fd9\u4e2a\u5305\u65f6\uff0c\u53ea\u4f1a\u4ece\u4e00\u4e2a\u6ce8\u518c\u6765\u6e90\u53bb\u88c5\uff0c\u8981\u4e48\u662f npm \u8981\u4e48\u662f bower, \u9632\u6b62\u51fa\u73b0\u6df7\u4e71\u4e0d\u4e00\u81f4\u3002<\/li><li><strong>\u66f4\u597d\u7684\u8bed\u4e49\u5316<\/strong>\uff1a yarn\u6539\u53d8\u4e86\u4e00\u4e9bnpm\u547d\u4ee4\u7684\u540d\u79f0\uff0c\u6bd4\u5982 yarn add\/remove\uff0c\u611f\u89c9\u4e0a\u6bd4 npm \u539f\u672c\u7684 install\/uninstall \u8981\u66f4\u6e05\u6670\u3002<\/li><\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">Yarn\u548cnpm\u547d\u4ee4\u5bf9\u6bd4<br><\/h5>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/11\/image-78-1024x357.png\" alt=\"\" class=\"wp-image-4151\" width=\"639\" height=\"222\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/11\/image-78-1024x357.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/11\/image-78-300x105.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/11\/image-78-768x268.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/11\/image-78-830x289.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/11\/image-78-230x80.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/11\/image-78-350x122.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/11\/image-78-480x167.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/11\/image-78.png 1366w\" sizes=\"(max-width: 639px) 100vw, 639px\" \/><\/figure><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">npm\u7684\u672a\u6765\uff1anpm5.0<br><\/h5>\n\n\n\n<p>\u6709\u4e86yarn\u7684\u538b\u529b\u4e4b\u540e\uff0cnpm\u505a\u4e86\u4e00\u4e9b\u7c7b\u4f3c\u7684\u6539\u8fdb\u3002<\/p>\n\n\n\n<ol><li>\u9ed8\u8ba4\u65b0\u589e\u4e86\u7c7b\u4f3cyarn.lock\u7684 package-lock.json\uff1b<\/li><li>git \u4f9d\u8d56\u652f\u6301\u4f18\u5316\uff1a\u8fd9\u4e2a\u7279\u6027\u5728\u9700\u8981\u5b89\u88c5\u5927\u91cf\u5185\u90e8\u9879\u76ee\uff08\u4f8b\u5982\u5728\u6ca1\u6709\u81ea\u5efa\u6e90\u7684\u5185\u7f51\u5f00\u53d1\uff09\uff0c\u6216\u9700\u8981\u4f7f\u7528\u67d0\u4e9b\u4f9d\u8d56\u7684\u672a\u53d1\u5e03\u7248\u672c\u65f6\u5f88\u6709\u7528\u3002\u5728\u8fd9\u4e4b\u524d\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u6307\u5b9a commit_id \u7684\u65b9\u5f0f\u6765\u63a7\u5236\u7248\u672c\u3002<\/li><li>\u6587\u4ef6\u4f9d\u8d56\u4f18\u5316\uff1a\u5728\u4e4b\u524d\u7684\u7248\u672c\uff0c\u5982\u679c\u5c06\u672c\u5730\u76ee\u5f55\u4f5c\u4e3a\u4f9d\u8d56\u6765\u5b89\u88c5\uff0c\u5c06\u4f1a\u628a\u6587\u4ef6\u76ee\u5f55\u4f5c\u4e3a\u526f\u672c\u62f7\u8d1d\u5230 node_modules \u4e2d\u3002\u800c\u5728 npm5 \u4e2d\uff0c\u5c06\u6539\u4e3a\u4f7f\u7528\u521b\u5efa symlinks \u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\uff08\u4f7f\u7528\u672c\u5730 tarball \u5305\u9664\u5916\uff09\uff0c\u800c\u4e0d\u518d\u6267\u884c\u6587\u4ef6\u62f7\u8d1d\u3002\u8fd9\u5c06\u4f1a\u63d0\u5347\u5b89\u88c5\u901f\u5ea6\u3002\u76ee\u524dyarn\u8fd8\u4e0d\u652f\u6301\u3002<\/li><\/ol>\n\n\n\n<h5 class=\"wp-block-heading\">\u603b\u7ed3<\/h5>\n\n\n\n<p>\u5728npm5.0\u4e4b\u524d\uff0cyarn\u7684\u4f18\u52bf\u7279\u522b\u660e\u663e\u3002\u4f46\u662f\u5728npm\u4e4b\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0a\u4e00\u7cfb\u5217\u5bf9\u6bd4\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 npm5 \u5728\u901f\u5ea6\u548c\u4f7f\u7528\u4e0a\u786e\u5b9e\u6709\u4e86\u5f88\u5927\u63d0\u5347\uff0c\u503c\u5f97\u5c1d\u8bd5\uff0c\u4e0d\u8fc7\u8fd8\u6ca1\u6709\u8d85\u8fc7yarn\u3002<\/p>\n\n\n\n<p>\u7efc\u4e0a\u6211\u4e2a\u4eba\u7684\u5efa\u8bae\u662f\u5982\u679c\u4f60\u5df2\u7ecf\u5728\u4e2a\u4eba\u9879\u76ee\u4e0a\u4f7f\u7528 yarn\uff0c\u5e76\u4e14\u6ca1\u6709\u9047\u5230\u66f4\u591a\u95ee\u9898\uff0c\u76ee\u524d\u5b8c\u5168\u53ef\u4ee5\u7ee7\u7eed\u4f7f\u7528\u3002\u4f46\u5982\u679c\u6709\u517c\u5bb9 npm \u7684\u573a\u666f\uff0c\u6216\u8005\u8eab\u5904\u5728\u4f7f\u7528 npm\uff0ccnpm\uff0ctnpm \u7684\u56e2\u961f\uff0c\u4ee5\u53ca\u8fd8\u6ca1\u6709\u5207\u5230 yarn \u7684\u9879\u76ee\uff0c\u90a3\u73b0\u5728\u5c31\u53ef\u4ee5\u8bd5\u4e00\u8bd5 npm5 \u4e86\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5047\u5982\u6211\u4eec\u8981\u8fd0\u884c\u4e00\u4e0b\u57fa\u4e8eReact\u7684\u65b0\u9879\u76ee\u3002\u6309\u7167\u4ee5\u5f80\uff0cnpm\u7684\u6b65\u9aa4\u90fd\u662f\uff1a \u8fd9\u65f6\uff0c\u6765\u4e86\u4e0b\u9762\u4e00\u6bb5 \u201c\u54a6\uff0cyarn\u662f\u4ec0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4148"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4148"}],"version-history":[{"count":3,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4148\/revisions"}],"predecessor-version":[{"id":4153,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4148\/revisions\/4153"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}