{"id":19638,"date":"2025-04-19T02:06:32","date_gmt":"2025-04-18T18:06:32","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/19638.html"},"modified":"2025-04-19T02:06:32","modified_gmt":"2025-04-18T18:06:32","slug":"next-js-%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97%ef%bc%9a%e6%b7%b1%e5%85%a5%e6%9e%84%e5%bb%ba%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%b8%b2%e6%9f%93%e7%9a%84%e7%8e%b0%e4%bb%a3-web-%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/19638.html","title":{"rendered":"Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\n<ul>\n<li>\u524d\u8a00<\/li>\n<li>\u4e00\u3001\u5b89\u88c5 Next.js<\/li>\n<li>\u4e8c\u3001\u914d\u7f6e Next.js<\/li>\n<li>\u4e09\u3001\u9875\u9762\u8def\u7531<\/li>\n<li>\u56db\u3001API \u8def\u7531<\/li>\n<li>\u4e94\u3001\u6570\u636e\u83b7\u53d6<\/li>\n<li>\u516d\u3001\u90e8\u7f72 Next.js \u5e94\u7528<\/li>\n<li>\u7ed3\u8bed<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u524d\u8a00<\/h3>\n<p>Next.js \u662f\u4e00\u4e2a\u57fa\u4e8e React \u7684\u5f00\u6e90\u6846\u67b6&#xff0c;\u7528\u4e8e\u6784\u5efa\u670d\u52a1\u7aef\u6e32\u67d3&#xff08;SSR&#xff09;\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u7b80\u5316\u4e86\u8bb8\u591a\u590d\u6742\u7684\u914d\u7f6e&#xff0c;\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u4e13\u6ce8\u4e8e\u7f16\u5199\u5e94\u7528\u903b\u8f91\u800c\u4e0d\u662f\u57fa\u7840\u8bbe\u65bd\u3002\u672c\u6307\u5357\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Next.js \u6784\u5efa\u4e00\u4e2a\u5b8c\u6574\u7684\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5305\u62ec\u5b89\u88c5\u3001\u914d\u7f6e\u3001\u8def\u7531\u3001API \u8def\u7531\u7b49\u65b9\u9762\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u5b89\u88c5 Next.js<\/h3>\n<p>\u9996\u5148&#xff0c;\u786e\u4fdd\u4f60\u7684\u673a\u5668\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86 Node.js\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c node -v \u547d\u4ee4\u6765\u68c0\u67e5\u662f\u5426\u5df2\u5b89\u88c5\u4ee5\u53ca\u5b89\u88c5\u7684\u7248\u672c\u3002\u5982\u679c\u5c1a\u672a\u5b89\u88c5&#xff0c;\u8bf7\u8bbf\u95ee Node.js\u5b98\u65b9\u7f51\u7ad9 \u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002<\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26&#xff0c;\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Next.js \u5e94\u7528&#xff1a;<\/p>\n<p>npx create-next-app&#064;latest my-next-app<\/p>\n<p>\u6309\u7167\u63d0\u793a\u5b8c\u6210\u9879\u76ee\u521d\u59cb\u5316\u3002\u8fd9\u4e00\u6b65\u4f1a\u8be2\u95ee\u4f60\u5173\u4e8e\u9879\u76ee\u7684\u4e00\u4e9b\u57fa\u672c\u4fe1\u606f&#xff0c;\u6bd4\u5982\u662f\u5426\u4f7f\u7528 TypeScript\u3001ESLint \u7b49\u3002\u5b8c\u6210\u540e&#xff0c;\u8fdb\u5165\u9879\u76ee\u76ee\u5f55&#xff1a;<\/p>\n<p><span class=\"token builtin class-name\">cd<\/span> my-next-app<\/p>\n<p>\u542f\u52a8\u5f00\u53d1\u670d\u52a1\u5668\u4ee5\u67e5\u770b\u5e94\u7528\u662f\u5426\u6b63\u5e38\u5de5\u4f5c&#xff1a;<\/p>\n<p><span class=\"token function\">npm<\/span> run dev<\/p>\n<p>\u73b0\u5728&#xff0c;\u4f60\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee http:\/\/localhost:3000 \u67e5\u770b\u4f60\u7684 Next.js \u5e94\u7528\u3002<\/p>\n<h3>\u4e8c\u3001\u914d\u7f6e Next.js<\/h3>\n<p>Next.js \u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ed8\u8ba4\u914d\u7f6e&#xff0c;\u9002\u5408\u5927\u591a\u6570\u5e94\u7528\u573a\u666f\u3002\u7136\u800c&#xff0c;\u6709\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u9700\u8981\u8fdb\u884c\u989d\u5916\u7684\u5b9a\u5236\u5316\u914d\u7f6e\u3002\u8fd9\u4e9b\u914d\u7f6e\u901a\u5e38\u653e\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e0b\u7684 next.config.js \u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u81ea\u5b9a\u4e49\u73af\u5883\u53d8\u91cf \u4f60\u53ef\u4ee5\u5728 .env.local \u6587\u4ef6\u4e2d\u5b9a\u4e49\u73af\u5883\u53d8\u91cf&#xff0c;\u8fd9\u4e9b\u53d8\u91cf\u5c06\u5728\u8fd0\u884c\u65f6\u53ef\u7528\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>NEXT_PUBLIC_API_URL&#061;https:\/\/api.example.com<\/p>\n<p>\u6ce8\u610f\u524d\u7f00 NEXT_PUBLIC_&#xff0c;\u53ea\u6709\u8fd9\u6837\u5b9a\u4e49\u7684\u53d8\u91cf\u624d\u80fd\u5728\u5ba2\u6237\u7aef\u4ee3\u7801\u4e2d\u8bbf\u95ee\u3002<\/p>\n<p>\u4fee\u6539 Webpack \u914d\u7f6e \u5982\u679c\u4f60\u60f3\u6269\u5c55\u6216\u4fee\u6539 Webpack \u914d\u7f6e&#xff0c;\u53ef\u4ee5\u5728 next.config.js \u4e2d\u8fd9\u6837\u505a&#xff1a;<\/p>\n<p>module<span class=\"token punctuation\">.<\/span>exports <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token function-variable function\">webpack<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">config<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span> isServer <span class=\"token punctuation\">}<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6269\u5c55\u914d\u7f6e<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>isServer<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n      config<span class=\"token punctuation\">.<\/span>resolve<span class=\"token punctuation\">.<\/span>fallback <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        fs<span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        net<span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n      <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> config<span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h3>\u4e09\u3001\u9875\u9762\u8def\u7531<\/h3>\n<p>\u521b\u5efa\u9759\u6001\u9875\u9762 \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u9759\u6001\u9875\u9762\u975e\u5e38\u76f4\u63a5\u3002\u5728 pages \u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 .js \u6587\u4ef6&#xff0c;\u5e76\u5bfc\u51fa\u4e00\u4e2a\u51fd\u6570\u7ec4\u4ef6&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ pages\/about.js<\/span><br \/>\n<span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">AboutPage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token operator\">&lt;<\/span>div<span class=\"token operator\">&gt;<\/span><br \/>\n      <span class=\"token operator\">&lt;<\/span>h1<span class=\"token operator\">&gt;<\/span>About Us<span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>h1<span class=\"token operator\">&gt;<\/span><br \/>\n      <span class=\"token operator\">&lt;<\/span>p<span class=\"token operator\">&gt;<\/span>Welcome to our about page<span class=\"token operator\">!<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>p<span class=\"token operator\">&gt;<\/span><br \/>\n    <span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">&gt;<\/span><br \/>\n  <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u52a8\u6001\u8def\u7531 \u52a8\u6001\u8def\u7531\u5141\u8bb8\u4f60\u6839\u636e URL \u53c2\u6570\u663e\u793a\u4e0d\u540c\u7684\u5185\u5bb9\u3002\u4f8b\u5982&#xff0c;\u535a\u5ba2\u6587\u7ae0\u53ef\u4ee5\u6839\u636e\u5176 ID \u663e\u793a\u7279\u5b9a\u7684\u6587\u7ae0&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ pages\/posts\/[id].js<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> useRouter <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;next\/router&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">Post<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> router <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">useRouter<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> <span class=\"token punctuation\">{<\/span> id <span class=\"token punctuation\">}<\/span> <span class=\"token operator\">&#061;<\/span> router<span class=\"token punctuation\">.<\/span>query<span class=\"token punctuation\">;<\/span><\/p>\n<p>  <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&lt;<\/span>div<span class=\"token operator\">&gt;<\/span>Post<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span>id<span class=\"token punctuation\">}<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>\u56db\u3001API \u8def\u7531<\/h3>\n<p>\u521b\u5efa API \u8def\u7531 Next.js \u5185\u7f6e\u4e86 API \u8def\u7531\u7684\u652f\u6301&#xff0c;\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u9879\u76ee\u4e2d\u5904\u7406\u524d\u7aef\u548c\u540e\u7aef\u903b\u8f91\u3002API \u8def\u7531\u4f4d\u4e8e pages\/api \u76ee\u5f55\u4e0b\u3002 \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 API \u8def\u7531\u6765\u54cd\u5e94 GET \u8bf7\u6c42&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ pages\/api\/hello.js<\/span><br \/>\n<span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">handler<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">status<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">200<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">json<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span> name<span class=\"token operator\">:<\/span> <span class=\"token string\">&#039;John Doe&#039;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd9\u4e2a API \u53ef\u4ee5\u901a\u8fc7\u53d1\u9001 HTTP GET \u8bf7\u6c42\u5230 \/api\/hello \u6765\u8c03\u7528\u3002<\/p>\n<h3>\u4e94\u3001\u6570\u636e\u83b7\u53d6<\/h3>\n<p>\u9759\u6001\u751f\u6210 \u5982\u679c\u4f60\u7684\u6570\u636e\u4e0d\u9700\u8981\u7ecf\u5e38\u66f4\u65b0&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u9759\u6001\u751f\u6210&#xff08;SSG&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ pages\/posts\/[id].js<\/span><br \/>\n<span class=\"token keyword\">export<\/span> <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">getStaticProps<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">context<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> res <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> <span class=\"token function\">fetch<\/span><span class=\"token punctuation\">(<\/span><span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token string\">https:\/\/&#8230;\/posts\/<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span>context<span class=\"token punctuation\">.<\/span>params<span class=\"token punctuation\">.<\/span>id<span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> post <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> res<span class=\"token punctuation\">.<\/span><span class=\"token function\">json<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>  <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    props<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n      post<span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">Post<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\"><span class=\"token punctuation\">{<\/span> post <span class=\"token punctuation\">}<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&lt;<\/span>div<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">{<\/span>post<span class=\"token punctuation\">.<\/span>title<span class=\"token punctuation\">}<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u670d\u52a1\u7aef\u6e32\u67d3 \u5bf9\u4e8e\u9700\u8981\u5728\u6bcf\u6b21\u8bf7\u6c42\u65f6\u90fd\u83b7\u53d6\u6700\u65b0\u6570\u636e\u7684\u60c5\u51b5&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u670d\u52a1\u7aef\u6e32\u67d3&#xff08;SSR&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ pages\/posts\/[id].js<\/span><br \/>\n<span class=\"token keyword\">export<\/span> <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">getServerSideProps<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">context<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> res <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> <span class=\"token function\">fetch<\/span><span class=\"token punctuation\">(<\/span><span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token string\">https:\/\/&#8230;\/posts\/<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span>context<span class=\"token punctuation\">.<\/span>params<span class=\"token punctuation\">.<\/span>id<span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> post <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> res<span class=\"token punctuation\">.<\/span><span class=\"token function\">json<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>  <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    props<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n      post<span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">Post<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\"><span class=\"token punctuation\">{<\/span> post <span class=\"token punctuation\">}<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&lt;<\/span>div<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">{<\/span>post<span class=\"token punctuation\">.<\/span>title<span class=\"token punctuation\">}<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>\u516d\u3001\u90e8\u7f72 Next.js \u5e94\u7528<\/h3>\n<p>\u6784\u5efa\u751f\u4ea7\u7248\u672c \u8981\u6784\u5efa\u751f\u4ea7\u7248\u672c\u7684\u5e94\u7528&#xff0c;\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p><span class=\"token function\">npm<\/span> run build<\/p>\n<p>\u542f\u52a8\u670d\u52a1\u5668 \u6784\u5efa\u5b8c\u6210\u540e&#xff0c;\u542f\u52a8\u751f\u4ea7\u670d\u52a1\u5668&#xff1a;<\/p>\n<p><span class=\"token function\">npm<\/span> start<\/p>\n<p>\u90e8\u7f72\u9009\u9879<\/p>\n<ul>\n<li>Vercel&#xff1a;Next.js \u7684\u5b98\u65b9\u90e8\u7f72\u5e73\u53f0&#xff0c;\u63d0\u4f9b\u4e00\u952e\u90e8\u7f72\u529f\u80fd\u3002<\/li>\n<li>Netlify&#xff1a;\u652f\u6301\u9759\u6001\u7ad9\u70b9\u548c API \u8def\u7531\u7684\u90e8\u7f72\u3002<\/li>\n<li>\u4f20\u7edf\u670d\u52a1\u5668&#xff1a;\u53ef\u4ee5\u5c06\u6784\u5efa\u540e\u7684\u5e94\u7528\u4e0a\u4f20\u5230\u4efb\u4f55\u652f\u6301 Node.js \u7684\u670d\u52a1\u5668\u4e0a\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u7ed3\u8bed<\/h3>\n<p>\u901a\u8fc7\u8fd9\u7bc7\u8be6\u7ec6\u7684\u6307\u5357&#xff0c;\u4f60\u5e94\u8be5\u5df2\u7ecf\u638c\u63e1\u4e86\u4f7f\u7528 Next.js \u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u5e94\u7528\u7684\u57fa\u672c\u6280\u80fd\u3002Next.js \u7684\u8bbe\u8ba1\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5f00\u53d1\u9ad8\u6027\u80fd\u7684 Web \u5e94\u7528&#xff0c;\u540c\u65f6\u4fdd\u6301\u826f\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u4e3a\u4f60\u5f00\u542f\u65b0\u7684\u5f00\u53d1\u4e4b\u65c5\u63d0\u4f9b\u5e2e\u52a9&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.6k\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u6700\u597d\u7684\u4ee3\u7801\u662f\u5199\u5f97\u6700\u5c11\u7684\u4ee3\u7801\u3002_nextjs<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[943,723,1521],"topic":[],"class_list":["post-19638","post","type-post","status-publish","format-standard","hentry","category-server","tag-next-js","tag-react","tag-1521"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/19638.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.6k\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u6700\u597d\u7684\u4ee3\u7801\u662f\u5199\u5f97\u6700\u5c11\u7684\u4ee3\u7801\u3002_nextjs\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/19638.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T18:06:32+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/19638.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/19638.html\",\"name\":\"Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T18:06:32+00:00\",\"dateModified\":\"2025-04-18T18:06:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/19638.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/19638.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/19638.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/19638.html","og_locale":"zh_CN","og_type":"article","og_title":"Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.6k\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u6700\u597d\u7684\u4ee3\u7801\u662f\u5199\u5f97\u6700\u5c11\u7684\u4ee3\u7801\u3002_nextjs","og_url":"https:\/\/www.wsisp.com\/helps\/19638.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T18:06:32+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/19638.html","url":"https:\/\/www.wsisp.com\/helps\/19638.html","name":"Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T18:06:32+00:00","dateModified":"2025-04-18T18:06:32+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/19638.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/19638.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/19638.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Next.js \u5165\u95e8\u6307\u5357\uff1a\u6df1\u5165\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684\u73b0\u4ee3 Web \u5e94\u7528"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/19638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=19638"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/19638\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=19638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=19638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=19638"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=19638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}