{"id":5272,"date":"2026-03-15T13:36:48","date_gmt":"2026-03-15T05:36:48","guid":{"rendered":"https:\/\/blog.smallken.ink\/?p=5272"},"modified":"2026-03-15T13:36:48","modified_gmt":"2026-03-15T05:36:48","slug":"%e6%95%99%e5%ad%b8-%e5%a6%82%e4%bd%95%e5%b0%87-vite-react-%e5%b0%88%e6%a1%88%e9%80%8f%e9%81%8e-github-actions-%e8%87%aa%e5%8b%95%e9%83%a8%e7%bd%b2%ef%bc%8c%e4%b8%a6%e7%b6%81%e5%ae%9a-namecheap","status":"publish","type":"post","link":"https:\/\/blog.smallken.site\/?p=5272","title":{"rendered":"[\u6559\u5b78] \u5982\u4f55\u5c07 Vite React \u5c08\u6848\u900f\u904e GitHub Actions \u81ea\u52d5\u90e8\u7f72\uff0c\u4e26\u7d81\u5b9a Namecheap \u81ea\u8a02\u7db2\u57df (\u4e3b\u7db2\u57df\/\u5b50\u7db2\u57df\u4e00\u6b21\u641e\u5b9a)"},"content":{"rendered":"\n<p>\u7576\u6211\u5011\u7528 Vite \u958b\u767c\u5b8c React \u5c08\u6848\u5f8c\uff0c\u5c07\u5b83\u90e8\u7f72\u5230 GitHub Pages \u662f\u4e00\u500b\u514d\u8cbb\u53c8\u65b9\u4fbf\u7684\u9078\u64c7\u3002\u4f46\u5982\u679c\u60f3\u8b93\u4f5c\u54c1\u770b\u8d77\u4f86\u66f4\u5c08\u696d\uff0c\u7d81\u5b9a\u81ea\u5df1\u7684\u5c08\u5c6c\u7db2\u57df\uff08\u4f8b\u5982 <code>yourdomain.com<\/code>\uff09\u7d55\u5c0d\u662f\u5fc5\u7d93\u4e4b\u8def\u3002<\/p>\n\n\n\n<p>\u9019\u7bc7\u6587\u7ae0\u5c07\u5e36\u4f60\u8d70\u904e\u5b8c\u6574\u7684\u6d41\u7a0b\uff1a\u5f9e <strong>Namecheap \u7684 DNS \u8a2d\u5b9a<\/strong>\u3001<strong>Vite \u5c08\u6848\u7684\u7db2\u57df\u8a2d\u5b9a<\/strong>\uff0c\u5230\u900f\u904e <strong>GitHub Actions \u81ea\u52d5\u5316\u90e8\u7f72<\/strong>\uff0c\u4e00\u6b21\u641e\u5b9a\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udee0\ufe0f \u4e8b\u524d\u6e96\u5099<\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u4e00\u500b\u4f7f\u7528 Vite \u5efa\u7acb\u7684 React \u5c08\u6848\u3002<\/li>\n\n\n\n<li>\u5df2\u7d93\u5c07\u7a0b\u5f0f\u78bc\u63a8\u4e0a GitHub \u5132\u5b58\u5eab\u3002<\/li>\n\n\n\n<li>\u5728 Namecheap\uff08\u6216\u5176\u4ed6\u7db2\u57df\u5546\uff09\u64c1\u6709\u4e00\u7d44\u81ea\u5df1\u7684\u7db2\u57df\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6b65\u9a5f\u4e00\uff1a\u5728 Namecheap \u8a2d\u5b9a DNS<\/h2>\n\n\n\n<p>\u767b\u5165 Namecheap\uff0c\u9032\u5165\u4f60\u7db2\u57df\u7684 <strong>Advanced DNS<\/strong> \u8a2d\u5b9a\u9801\u9762\u3002\u5728\u958b\u59cb\u65b0\u589e\u7d00\u9304\u524d\uff0c\u8acb\u5148<strong>\u522a\u9664\u7cfb\u7d71\u9810\u8a2d\u7684\u7d00\u9304<\/strong>\uff08\u4f8b\u5982\u6307\u5411\u505c\u8eca\u9801\u9762\u7684 CNAME \u6216 A Record\uff09\uff0c\u78ba\u4fdd\u5217\u8868\u4e7e\u6de8\uff0c\u4ee5\u514d\u6d41\u91cf\u88ab\u5c0e\u5411\u932f\u8aa4\u7684\u4f3a\u670d\u5668\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u4f86\uff0c\u8acb\u6839\u64da\u4f60\u7684\u9700\u6c42\u9078\u64c7 <strong>\u300c\u4e3b\u7db2\u57df\u300d<\/strong> \u6216 <strong>\u300c\u5b50\u7db2\u57df\u300d<\/strong> \u7684\u8a2d\u5b9a\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6848 A\uff1a\u4f7f\u7528\u4e3b\u7db2\u57df (\u4f8b\u5982 <code>abc.ink<\/code>)<\/h3>\n\n\n\n<p>\u5982\u679c\u4f60\u60f3\u8b93\u8a2a\u5ba2\u76f4\u63a5\u8f38\u5165\u7db2\u57df\u5c31\u80fd\u770b\u5230\u5c08\u6848\uff0c\u4f60\u9700\u8981\u65b0\u589e 4 \u7b46\u6307\u5411 GitHub \u4f3a\u670d\u5668\u7684 <strong>A Record<\/strong>\u3002<\/p>\n\n\n\n<p>\u9ede\u64ca <strong>Add New Record<\/strong>\uff0c\u4e26\u91cd\u8907\u65b0\u589e\u4ee5\u4e0b\u56db\u7b46\u7d00\u9304\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Type:<\/strong> <code>A Record<\/code> | <strong>Host:<\/strong> <code>@<\/code> | <strong>Value:<\/strong> <code>185.199.108.153<\/code><\/li>\n\n\n\n<li><strong>Type:<\/strong> <code>A Record<\/code> | <strong>Host:<\/strong> <code>@<\/code> | <strong>Value:<\/strong> <code>185.199.109.153<\/code><\/li>\n\n\n\n<li><strong>Type:<\/strong> <code>A Record<\/code> | <strong>Host:<\/strong> <code>@<\/code> | <strong>Value:<\/strong> <code>185.199.110.153<\/code><\/li>\n\n\n\n<li><strong>Type:<\/strong> <code>A Record<\/code> | <strong>Host:<\/strong> <code>@<\/code> | <strong>Value:<\/strong> <code>185.199.111.153<\/code><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\ud83d\udca1 \u88dc\u5145\uff1a<\/strong> \u901a\u5e38\u6211\u5011\u4e5f\u6703\u9806\u4fbf\u52a0\u4e00\u7b46 <strong>CNAME Record<\/strong> (Host \u586b <code>www<\/code>\uff0cValue \u586b <code>\u4f60\u7684\u5e33\u865f.github.io<\/code>)\uff0c\u9019\u6a23\u5225\u4eba\u7fd2\u6163\u6027\u6253 <code>www.abc.ink<\/code> \u6642\u4e5f\u80fd\u9806\u5229\u9023\u4e0a\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6848 B\uff1a\u4f7f\u7528\u5b50\u7db2\u57df (\u4f8b\u5982 <code>app.abc.ink<\/code>)<\/h3>\n\n\n\n<p>\u5982\u679c\u4f60\u7684\u4e3b\u7db2\u57df\u8981\u7559\u7d66\u5225\u7684\u7db2\u7ad9\uff0c\u5c08\u6848\u53ea\u60f3\u653e\u5728\u5b50\u7db2\u57df\uff0c\u90a3\u4f60\u53ea\u9700\u8981 1 \u7b46 <strong>CNAME Record<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Type:<\/strong> <code>CNAME Record<\/code><\/li>\n\n\n\n<li><strong>Host:<\/strong> \u586b\u5165\u4f60\u7684\u5b50\u7db2\u57df\u524d\u7db4\uff08\u4f8b\u5982 <code>app<\/code> \u6216 <code>demo<\/code>\uff09<\/li>\n\n\n\n<li><strong>Value:<\/strong> \u586b\u5165\u4f60\u7684 GitHub Pages \u9810\u8a2d\u7db2\u5740 <code>\u4f60\u7684\u5e33\u865f.github.io<\/code> (\u26a0\ufe0f \u6ce8\u610f\uff1a\u524d\u9762\u4e0d\u9700\u8981\u52a0 <code>https:\/\/<\/code>)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6b65\u9a5f\u4e8c\uff1a\u4fee\u6539 Vite \u5c08\u6848\u8a2d\u5b9a<\/h2>\n\n\n\n<p>\u56e0\u70ba\u6211\u5011\u63db\u4e86\u5c08\u5c6c\u7db2\u57df\uff0c\u7db2\u7ad9\u7684\u300c\u6839\u76ee\u9304\u300d\u6539\u8b8a\u4e86\uff0c\u4e14\u4f7f\u7528\u4e86\u81ea\u52d5\u5316\u90e8\u7f72\uff0c\u6240\u4ee5\u5fc5\u9808\u5728\u7a0b\u5f0f\u78bc\u4e2d\u505a\u5169\u9805\u95dc\u9375\u4fee\u6539\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u65b0\u589e CNAME \u6a94\u6848 (\u6700\u91cd\u8981\u7684\u4e00\u6b65\uff01)<\/h3>\n\n\n\n<p>\u70ba\u4e86\u8b93 GitHub \u77e5\u9053\u4f60\u8981\u7d81\u5b9a\u54ea\u500b\u7db2\u57df\uff0c\u6211\u5011\u9700\u8981\u5efa\u7acb\u4e00\u500b <code>CNAME<\/code> \u6a94\u6848\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u5c08\u6848\u7684 <strong>\u6839\u76ee\u9304<\/strong> \u627e\u5230\uff08\u6216\u624b\u52d5\u5efa\u7acb\uff09\u4e00\u500b\u540d\u70ba <code>public<\/code> \u7684\u8cc7\u6599\u593e\u3002<\/li>\n\n\n\n<li>\u5728 <code>public<\/code> \u8cc7\u6599\u593e\u5167\uff0c\u65b0\u589e\u4e00\u500b\u540d\u70ba <strong><code>CNAME<\/code><\/strong> \u7684\u6a94\u6848\uff08\u26a0\ufe0f \u6ce8\u610f\uff1a\u5b57\u6bcd\u9700\u5168\u5927\u5beb\uff0c\u4e14<strong>\u4e0d\u8981<\/strong>\u6709\u4efb\u4f55\u526f\u6a94\u540d\u5982 <code>.txt<\/code>\uff09\u3002<\/li>\n\n\n\n<li>\u6253\u958b\u6a94\u6848\uff0c\u88e1\u9762\u53ea\u9700\u5beb\u5165\u4f60\u6700\u7d42\u6c7a\u5b9a\u7684\u7db2\u5740\uff0c\u4f8b\u5982\uff1aPlaintext<code>abc.ink <\/code><em>(\u5982\u679c\u4f60\u9078\u7684\u662f\u65b9\u6848 B\uff0c\u9019\u88e1\u5c31\u586b\u5beb <code>app.abc.ink<\/code>)<\/em><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\ud83d\udca1 \u539f\u7406\u63ed\u5bc6\uff1a<\/strong> Vite \u6253\u5305\u6642\u6703\u5c07 <code>public<\/code> \u5167\u7684\u6a94\u6848\u539f\u5c01\u4e0d\u52d5\u8907\u88fd\u5230\u8f38\u51fa\u7684 <code>dist<\/code> \u8cc7\u6599\u593e\u4e2d\u3002\u9019\u6a23\u7576 Actions \u5c07\u6253\u5305\u597d\u7684\u6a94\u6848\u4e0a\u50b3\u5230 GitHub \u6642\uff0c\u7cfb\u7d71\u5c31\u80fd\u81ea\u52d5\u8b80\u53d6\u5230\u9019\u4efd\u7db2\u57df\u8a2d\u5b9a\u6a94\uff01<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u66f4\u65b0 Base URL<\/h3>\n\n\n\n<p>\u6253\u958b\u5c08\u6848\u6839\u76ee\u9304\u7684 <code>vite.config.js<\/code> (\u6216 <code>.ts<\/code>)\uff0c\u78ba\u4fdd\u4f60\u7684 <code>base<\/code> \u8def\u5f91\u8a2d\u5b9a\u70ba\u6839\u76ee\u9304 <code>\/<\/code>\uff1a<\/p>\n\n\n\n<p>JavaScript<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { defineConfig } from 'vite'\nimport react from '@vitejs\/plugin-react'\n\nexport default defineConfig({\n  plugins: &#91;react()],\n  base: '\/', \/\/ \u78ba\u4fdd\u9019\u88e1\u662f\u55ae\u4e00\u659c\u7dda\n})\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6b65\u9a5f\u4e09\uff1a\u63a8\u64ad\u7a0b\u5f0f\u78bc\u8207\u81ea\u52d5\u90e8\u7f72<\/h2>\n\n\n\n<p>\u78ba\u8a8d\u4f60\u5df2\u7d93\u5728\u5c08\u6848\u4e2d\u8a2d\u5b9a\u597d\u4e86 GitHub Actions \u7684\u90e8\u7f72\u8173\u672c\uff08\u901a\u5e38\u4f4d\u65bc <code>.github\/workflows\/deploy.yml<\/code>\uff09\u3002<\/p>\n\n\n\n<p>\u63a5\u8457\uff0c\u6253\u958b\u7d42\u7aef\u6a5f\uff0c\u5c07\u525b\u525b\u7684\u4fee\u6539\u63a8\u4e0a GitHub\uff1a<\/p>\n\n\n\n<p>Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git add .\ngit commit -m \"Add CNAME and update base url for custom domain\"\ngit push\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83c\udf88 \u898b\u8b49\u5947\u8e5f\u7684\u6642\u523b<\/h3>\n\n\n\n<p>\u63a8\u64ad\u4e0a\u53bb\u5f8c\uff0cGitHub Actions \u5c31\u6703\u958b\u59cb\u81ea\u52d5\u6253\u5305\u3002<\/p>\n\n\n\n<p><strong>\u9019\u88e1\u6709\u4e00\u500b\u8d85\u65b9\u4fbf\u7684\u96b1\u85cf\u6a5f\u5236\uff1a<\/strong> \u904e\u53bb\u6211\u5011\u53ef\u80fd\u9700\u8981\u624b\u52d5\u5230 GitHub \u7684 Settings \u53bb\u586b\u5beb Custom domain\u3002\u4f46\u56e0\u70ba\u6211\u5011\u5728\u6b65\u9a5f\u4e8c\u5df2\u7d93\u628a <code>CNAME<\/code> \u6a94\u6848\u5305\u9032\u4e86\u6253\u5305\u6d41\u7a0b\u4e2d\uff0c\u7576 Actions \u90e8\u7f72\u5b8c\u6210\u5f8c\uff0c<strong>GitHub \u6703\u81ea\u52d5\u8b80\u53d6\u8a72\u6a94\u6848\uff0c\u4e26\u5728\u5f8c\u53f0\u5e6b\u4f60\u628a Custom domain \u586b\u5beb\u5b8c\u7562\uff01<\/strong> \u4f60\u53ea\u9700\u8981\u505a\u6700\u5f8c\u7684\u78ba\u8a8d\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u5230 GitHub \u5132\u5b58\u5eab\u7684 <strong>Settings > Pages<\/strong>\u3002<\/li>\n\n\n\n<li>\u5f80\u4e0b\u6372\u52d5\uff0c\u78ba\u8a8d Custom domain \u6b04\u4f4d\u5df2\u7d93\u81ea\u52d5\u51fa\u73fe\u4f60\u7684\u7db2\u57df\u3002<\/li>\n\n\n\n<li>\u7b49\u5f85 DNS \u6aa2\u67e5\u901a\u904e (\u986f\u793a\u7da0\u8272\u7684 <code>DNS check successful<\/code>)\u3002<\/li>\n\n\n\n<li>\u52fe\u9078\u4e0b\u65b9\u7684 <strong>Enforce HTTPS<\/strong>\uff08\u5982\u679c\u53cd\u7070\u4e0d\u80fd\u6309\uff0c\u8acb\u8010\u5fc3\u7b49\u500b 15~30 \u5206\u9418\uff0cGitHub \u6838\u767c\u514d\u8cbb SSL \u6191\u8b49\u9700\u8981\u4e00\u9ede\u6642\u9593\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u606d\u559c\uff01\u4f60\u7684 Vite React \u5c08\u6848\u73fe\u5728\u5df2\u7d93\u5728\u5c08\u5c6c\u7db2\u57df\u4e0a\u5b8c\u7f8e\u904b\u884c\uff0c\u4e26\u4e14\u64c1\u6709\u5b89\u5168\u7684 HTTPS \u9396\u982d\u6a19\u8a8c\u4e86\uff01\ud83c\udf89<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7576\u6211\u5011\u7528 Vite \u958b\u767c\u5b8c React \u5c08\u6848\u5f8c\uff0c\u5c07\u5b83\u90e8\u7f72\u5230 GitHub Pages \u662f\u4e00\u500b\u514d\u8cbb\u53c8\u65b9\u4fbf\u7684\u9078\u64c7\u3002&#8230;<\/p>\n","protected":false},"author":1,"featured_media":5273,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5272","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.smallken.site\/index.php?rest_route=\/wp\/v2\/posts\/5272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.smallken.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.smallken.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.smallken.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.smallken.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5272"}],"version-history":[{"count":1,"href":"https:\/\/blog.smallken.site\/index.php?rest_route=\/wp\/v2\/posts\/5272\/revisions"}],"predecessor-version":[{"id":5274,"href":"https:\/\/blog.smallken.site\/index.php?rest_route=\/wp\/v2\/posts\/5272\/revisions\/5274"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.smallken.site\/index.php?rest_route=\/wp\/v2\/media\/5273"}],"wp:attachment":[{"href":"https:\/\/blog.smallken.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.smallken.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.smallken.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}