{"id":10021030,"date":"2025-10-13T19:00:24","date_gmt":"2025-10-13T11:00:24","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021030"},"modified":"2025-10-13T19:00:24","modified_gmt":"2025-10-13T11:00:24","slug":"%e5%8a%a0%e9%80%9f%e4%bd%a0%e7%9a%84-bun-%e5%b9%b6%e8%a1%8c%e5%bc%80%e5%8f%91%ef%bc%9abun-tasks-%e5%85%a8%e6%94%bb%e7%95%a5","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021030","title":{"rendered":"\u52a0\u901f\u4f60\u7684 Bun \u5e76\u884c\u5f00\u53d1\uff1abun-tasks \u5168\u653b\u7565"},"content":{"rendered":"<h2>\u52a0\u901f\u4f60\u7684 Bun \u5e76\u884c\u5f00\u53d1\uff1a<code>bun-tasks<\/code> \u5168\u653b\u7565<\/h2>\n<p>\u5982\u679c\u4f60\u5728 Bun \u9879\u76ee\u91cc\u9700\u8981\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u811a\u672c\uff0c\u53c8\u4e0d\u60f3\u4e3a\u517c\u5bb9\u6027\u70e6\u5fc3\uff0c<code>bun-tasks<\/code> \u4f1a\u662f\u6700\u987a\u624b\u7684\u9009\u62e9\u3002\u8fd9\u4e2a\u4e13\u4e3a Bun \u8bbe\u8ba1\u7684\u5e76\u884c\u4efb\u52a1\u8fd0\u884c\u5668\uff0c\u5e2e\u4f60\u5728\u4e00\u6761\u547d\u4ee4\u4e2d\u542f\u52a8\u591a\u4e2a\u4efb\u52a1\u3001\u667a\u80fd\u5408\u5e76\u73af\u5883\u53d8\u91cf\uff0c\u5e76\u81ea\u52a8\u8bc6\u522b <code>package.json<\/code> \u4e2d\u7684\u811a\u672c\u3002\u53ea\u8981\u5148\u786e\u8ba4\u73af\u5883\u91cc <code>bun --version<\/code> \u53ef\u7528\uff0c\u5c31\u80fd\u5373\u523b\u4f53\u9a8c Bun \u539f\u751f\u7684\u591a\u4efb\u52a1\u6d41\u7a0b\u3002<\/p>\n<h3>\u4e3a\u4ec0\u4e48\u9009\u62e9 <code>bun-tasks<\/code><\/h3>\n<ul>\n<li><strong>\u4e13\u6ce8 Bun \u751f\u6001<\/strong>\uff1a\u5b8c\u5168\u57fa\u4e8e Bun \u8fd0\u884c\u65f6\u5f00\u53d1\uff0c\u65e0\u9700 Node \u517c\u5bb9\u5c42\uff0c\u5b89\u88c5\u914d\u7f6e\u66f4\u8f7b\u677e\u3002<\/li>\n<li><strong>\u76f4\u89c2\u7684\u547d\u4ee4\u5206\u9694\u7b26<\/strong>\uff1a\u4f7f\u7528 <code>:::<\/code> \u5c06\u591a\u4e2a\u547d\u4ee4\u4e32\u8054\uff0cBun \u4f1a\u6309\u539f\u6837\u4fdd\u7559\u5f15\u53f7\u548c\u7a7a\u683c\uff0c\u907f\u514d Shell \u5e72\u6270\u3002<\/li>\n<li><strong>\u7075\u6d3b\u7684\u73af\u5883\u53d8\u91cf\u6ce8\u5165<\/strong>\uff1a\u5168\u5c40 <code>--args<\/code> \/ <code>-a<\/code> \u4e0e\u547d\u4ee4\u7ea7\u53c2\u6570\u53ef\u53e0\u52a0\uff0c\u91cd\u590d\u952e\u4ee5\u547d\u4ee4\u7ea7\u4f18\u5148\u751f\u6548\u3002<\/li>\n<li><strong>\u81ea\u52a8\u811a\u672c\u6620\u5c04<\/strong>\uff1a\u76f4\u63a5\u5199\u811a\u672c\u540d\u79f0\uff0c\u5185\u90e8\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210 <code>bun run &lt;script&gt;<\/code>\uff0c\u65e0\u9700\u91cd\u590d\u8f93\u5165 Bun\u3002<\/li>\n<li><strong>\u539f\u6c41\u539f\u5473\u7684\u8f93\u51fa<\/strong>\uff1a\u5f00\u542f <code>--raw<\/code> \/ <code>-r<\/code> \u65f6\u5c06\u76f4\u63a5\u7ee7\u627f\u5b50\u8fdb\u7a0b\u7684\u6807\u51c6\u8f93\u51fa\uff0c\u5bf9\u4e8e Parcel \u7b49\u9700\u8981\u4fdd\u7559\u8fdb\u5ea6\u6761\u548c\u989c\u8272\u7684\u5de5\u5177\u5c24\u4e3a\u53cb\u597d\u3002<\/li>\n<li><strong>\u53ef\u7f16\u7a0b\u63a5\u53e3<\/strong>\uff1a\u5bfc\u51fa\u7684 <code>BunTasksCLI<\/code> \u7c7b\u4e0d\u4f1a\u5728 <code>import<\/code> \u65f6\u6267\u884c\uff0c\u65b9\u4fbf\u96c6\u6210\u5230\u81ea\u5b9a\u4e49\u811a\u672c\u6216\u670d\u52a1\u3002<\/li>\n<\/ul>\n<h3>\u5feb\u901f\u4e0a\u624b<\/h3>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u5230\u9879\u76ee<\/strong><\/p>\n<pre><code class=\"bash\">bun add -D bun-tasks<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u5728 <code>package.json<\/code> \u4e2d\u914d\u7f6e\u811a\u672c<\/strong><\/p>\n<pre><code class=\"json\">{\n  &quot;scripts&quot;: {\n    &quot;dev&quot;: &quot;bun-tasks --args NODE_ENV=dev api ::: docs --args PORT=4000&quot;\n  }\n}<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u5b9a\u4e49\u88ab\u8c03\u7528\u7684\u5b50\u547d\u4ee4<\/strong><\/p>\n<pre><code class=\"json\">{\n  &quot;scripts&quot;: {\n    &quot;api&quot;: &quot;bun run src\/api.ts&quot;,\n    &quot;docs&quot;: &quot;bun run docs:watch&quot;,\n    &quot;dev&quot;: &quot;bun-tasks api ::: docs&quot;\n  }\n}<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8\u5e76\u884c\u4efb\u52a1<\/strong><\/p>\n<pre><code class=\"bash\">bun run dev<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u8fd0\u884c\u540e\uff0c\u591a\u4e2a\u4efb\u52a1\u4f1a\u5e26\u7740\u7f16\u53f7\u524d\u7f00\u540c\u65f6\u8f93\u51fa\uff0c\u65e5\u5fd7\u6765\u6e90\u4e00\u76ee\u4e86\u7136\u3002<\/p>\n<h3>\u5e38\u7528\u53c2\u6570\u901f\u89c8<\/h3>\n<ul>\n<li><code>--help<\/code>, <code>-h<\/code>\uff1a\u67e5\u770b\u5e2e\u52a9\u3002<\/li>\n<li><code>--version<\/code>, <code>-v<\/code>\uff1a\u663e\u793a\u5f53\u524d\u7248\u672c\u3002<\/li>\n<li><code>--args<\/code>, <code>-a<\/code>\uff1a\u6ce8\u5165\u73af\u5883\u53d8\u91cf\uff0c\u652f\u6301\u5168\u5c40\u6216\u5355\u4e2a\u547d\u4ee4\u3002<\/li>\n<li><code>--raw<\/code>, <code>-r<\/code>\uff1a\u7ee7\u627f\u5b50\u8fdb\u7a0b\u8f93\u51fa\uff0c\u4fdd\u6301\u989c\u8272\u4e0e\u8fdb\u5ea6\u6761\u6548\u679c\u3002<\/li>\n<\/ul>\n<h3>\u7a0b\u5e8f\u5316\u8c03\u7528\u793a\u4f8b<\/h3>\n<pre><code class=\"ts\">import { BunTasksCLI } from &quot;bun-tasks&quot;;\n\nconst cli = new BunTasksCLI();\nawait cli.run([&quot;echo&quot;, &quot;hello&quot;, &quot;:::&quot;, &quot;echo&quot;, &quot;world&quot;], {\n  stdoutPrefix: (index) =&gt; `[job-${index}]`,\n  mirrorStderrToStdout: true,\n});<\/code><\/pre>\n<p>\u8be5\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u5728\u81ea\u5b9a\u4e49\u811a\u672c\u4e2d\u590d\u7528 <code>bun-tasks<\/code> \u7684\u6838\u5fc3\u903b\u8f91\uff0c\u8f93\u51fa\u524d\u7f00\u548c\u9519\u8bef\u955c\u50cf\u90fd\u80fd\u7075\u6d3b\u63a7\u5236\u3002<\/p>\n<h3>\u5f00\u53d1\u4e0e\u6d4b\u8bd5\u5efa\u8bae<\/h3>\n<pre><code class=\"bash\">bun install\nbun test --coverage<\/code><\/pre>\n<blockquote><p>\u63d0\u793a\uff1aBun \u5728\u539f\u751f Windows \u4e0a\u7684\u8986\u76d6\u7387\u8f93\u51fa\u4ecd\u5728\u5b8c\u5584\u4e2d\uff0c\u5982\u9047\u5f02\u5e38\u53ef\u6682\u65f6\u53bb\u6389 <code>--coverage<\/code> \u6216\u5728 WSL \u4e2d\u8fd0\u884c\u3002<\/p><\/blockquote>\n<h3>\u81f4\u8c22<\/h3>\n<p>\u672c\u9879\u76ee\u90e8\u5206\u4ee3\u7801\u7531 GPT-5-Codex \u534f\u52a9\u5b8c\u6210\u3002<\/p>\n<hr>\n<p>\u51c6\u5907\u597d\u7ed9 Bun \u4efb\u52a1\u7ba1\u7406\u63d0\u901f\u4e86\u5417\uff1f\u7acb\u5373\u4e0b\u8f7d\u5e76\u5173\u6ce8\u6700\u65b0\u8fdb\u5c55\uff1a<\/p>\n<ul>\n<li>npm\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=n36Lngo6V4R462mIyPueXw%3D%3D.1%2F9X2y5W0XhRamxqIXrHpb4yOAz2ZP12ZJWhW97zsdRiTeITZA8R29%2BU6ZW8fHSL\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.npmjs.com\/package\/bun-tasks<\/a><\/li>\n<li>GitHub\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=02hseb4fKtf2Z7LvgzPHPg%3D%3D.uHA77Azb2HmSpklxSFqTrLJjrHKblJNUxcgbL%2FtvNup%2FBa8xuwXA3oyj3ZkC1bx4\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/gxy5202\/bun-tasks<\/a><\/li>\n<\/ul>\n<p>\u8ba9 <code>bun-tasks<\/code> \u5e2e\u4f60\u4fdd\u6301 Bun \u7684\u901f\u5ea6\u4e0e\u5e76\u884c\u6548\u7387\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047318023\">https:\/\/segmentfault.com\/a\/1190000047318023<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u52a0\u901f\u4f60\u7684 Bun \u5e76\u884c\u5f00\u53d1\uff1abun-tasks \u5168\u653b\u7565 \u5982\u679c\u4f60\u5728 Bun \u9879\u76ee\u91cc\u9700\u8981\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u811a\u672c\uff0c\u53c8\u4e0d\u60f3\u4e3a [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021030","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021030"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021030\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}