{"id":1036,"date":"2023-03-12T09:48:05","date_gmt":"2023-03-12T01:48:05","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1036"},"modified":"2023-04-29T13:10:43","modified_gmt":"2023-04-29T05:10:43","slug":"how-to-choose-correct-node-framework-next-nuxt-next","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/how-to-choose-correct-node-framework-next-nuxt-next\/","title":{"rendered":"\u5982\u4f55\u9009\u62e9\u6b63\u786e\u7684Node\u6846\u67b6\uff1aNext, Nuxt, Nest\uff1f"},"content":{"rendered":"<p>Next\u3001Nuxt\u548cNest\u8fd9\u4e09\u4e2a\u6846\u67b6\u90fd\u662f\u670d\u52a1\u5668\u7aef\u6e32\u67d3\uff0c\u5b83\u4eec\u5206\u522b\u4e0eReact\u3001Vue\u548cAngular(\u4e09\u4e2a\u76ee\u524d\u6700\u6d41\u884c\u7684\u524d\u7aef\u6846\u67b6)\u5bc6\u5207\u76f8\u5173<\/p>\n<h2>Next<\/h2>\n<p>Next\u662f\u4e00\u4e2aReact\u6846\u67b6\uff0c\u5141\u8bb8\u4f7f\u7528React\u6784\u5efaSSR\u548c\u9759\u6001web\u5e94\u7528<\/p>\n<p><!-- more --><\/p>\n<p><strong>\u5b89\u88c5<\/strong><\/p>\n<p>next react react-dom\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684<\/p>\n<pre><code class=\"language-bash\">npm install --save next react react-dom<\/code><\/pre>\n<p><code>package.json<\/code>\u4e2d\u6dfb\u52a0\u811a\u672c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code class=\"language-javascript\">{\n  &quot;scripts&quot;: {\n    &quot;dev&quot;: &quot;next&quot;,\n    &quot;build&quot;: &quot;next build&quot;,\n    &quot;start&quot;: &quot;next start&quot;\n  }\n}<\/code><\/pre>\n<p>next \u5c06\u8bfb\u53d6page\u76ee\u5f55\u4e0b\u7684js\u6587\u4ef6\uff0c\u5e76\u89e3\u6790\u6210\u9875\u9762\u8def\u7531<\/p>\n<p><strong>Hello World<\/strong><\/p>\n<p>\u9879\u76ee\u5185\u521b\u5efa\u76ee\u5f55\u6587\u4ef6<code>.\/pages\/index.js<\/code><\/p>\n<pre><code class=\"language-javascript\">function Home() {\n  return &lt;div&gt;Hello world!&lt;\/div&gt;;\n}\n\nexport default Home;\n\n\/\/ npm run dev\n\/\/ \u7136\u540e\u8bbf\u95ee http:\/\/localhost:3000<\/code><\/pre>\n<p><strong>\u597d\u5904<\/strong><\/p>\n<ul>\n<li>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a\u7ec4\u4ef6\u90fd\u662f\u670d\u52a1\u5668\u6e32\u67d3\u7684<\/li>\n<li>\u81ea\u52a8\u4ee3\u7801\u62c6\u5206\uff0c\u52a0\u5feb\u9875\u9762\u52a0\u8f7d\u901f\u5ea6<\/li>\n<li>\u4e0d\u52a0\u8f7d\u4e0d\u5fc5\u8981\u7684\u4ee3\u7801<\/li>\n<li>\u7b80\u5355\u7684\u5ba2\u6237\u7aef\u8def\u7531\uff08\u57fa\u4e8e\u9875\u9762\uff09<\/li>\n<li>\u57fa\u4e8eWebpack\u7684\u5f00\u53d1\u73af\u5883\uff0c\u652f\u6301\u6a21\u5757\u70ed\u66f4\u65b0\uff08HMR\uff09<\/li>\n<li>\u83b7\u53d6\u6570\u636e\u975e\u5e38\u7b80\u5355<\/li>\n<li>\u652f\u6301\u4efb\u4f55Node HTTP\u670d\u52a1\u5668\u5b9e\u73b0\uff0c\u5982Express<\/li>\n<li>\u652f\u6301Babel\u548cWebpack\u81ea\u5b9a\u4e49<\/li>\n<li>\u80fd\u591f\u90e8\u7f72\u5728\u4efb\u4f55\u80fd\u8fd0\u884cnode\u7684\u5e73\u53f0<\/li>\n<li>\u5185\u7f6e\u9875\u9762\u641c\u7d22\u5f15\u64ce\u4f18\u5316\uff08SEO\uff09\u5904\u7406<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9<\/strong><\/p>\n<ul>\n<li>Next\u4e0d\u662f\u540e\u7aef\u670d\u52a1\uff0c\u5e94\u8be5\u4e0e\u540e\u53f0\u64cd\u4f5c\u72ec\u7acb\u5f00<\/li>\n<li>\u5982\u679c\u4f60\u53ea\u60f3\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684WEB\u5e94\u7528\uff0c\u90a3\u4e48\u5b83\u53ef\u80fd\u4f1a\u662f\u725b\u5200\u6740\u9e21<\/li>\n<li>\u6570\u636e\u4f1a\u5728\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u91cd\u590d\u52a0\u8f7d<\/li>\n<li>\u6ca1\u6709\u5b9e\u73b0\u524d\u540e\u5206\u79bb\u7684\u9879\u76ee\uff0c\u8fc1\u79fb\u5230Next\u662f\u4e00\u4ef6\u75db\u82e6\u7684\u4e8b\uff0c\u53ef\u80fd\u9700\u8981\u53cc\u500d\u5de5\u4f5c<\/li>\n<\/ul>\n<p><strong>\u6027\u80fd<\/strong><\/p>\n<p>\u6027\u80fd\u57fa\u4e8e\u4ee5\u4e0b\u4e24\u70b9<\/p>\n<p>1\u3001\u4f7f\u7528Apache Bench\u6d4b\u8bd5\u541e\u5410\u91cf<\/p>\n<p>\u7ecf\u6d4b\u8bd5\uff0cNext\u57fa\u672cHelloWorld\u7a0b\u5e8f\u3002\u6bcf\u79d2\u80fd\u5904\u7406550.87\u4e2a\u8bf7\u6c42\u3002\u6bcf\u4e2a\u8bf7\u6c42\u82b1\u8d39\u7684\u5e73\u5747\u65f6\u95f4\u4e3a18.153ms<\/p>\n<p>2\u3001\u4f7f\u7528 lighthouse\u6d4b\u8bd5 Preformance\u3001Accessibility\u3001Best Practices\u3001SEO<\/p>\n<p>lighthouse\u6d4b\u8bd5\u62a5\u544a\u4e2d\u53ef\u4ee5\u770b\u5230Preformance\u3001Accessibility\u3001Best Practices\u3001SEO\u90fd\u9ad8\u4e8e70\uff0c\u867d\u7136\u6bd4\u5176\u4ed6\u4e24\u4e2a\u6846\u67b6\u4f4e\uff0c\u4f46\u4e0d\u5f97\u4e0d\u8bf4\u5df2\u7ecf\u662f\u4e00\u4e2a\u6bd4\u8f83\u597d\u7684\u6570\u636e\uff0cBest Practices \u5f97\u5206nuxt\u5219\u662f\u9ad8\u4e8e\u5176\u4ed6\u4fe9\u4e2a<\/p>\n<h2>Nuxt<\/h2>\n<p>Nuxt\u662f\u4e00\u4e2a\u57fa\u4e8eVue\u7684\u901a\u7528\u5e94\u7528\u6846\u67b6\uff0c\u9884\u8bbe\u4e86\u5229\u7528Vue\u5f00\u53d1\u670d\u52a1\u7aef\u6e32\u67d3\u7684\u5e94\u7528\u6240\u9700\u8981\u7684\u5404\u79cd\u914d\u7f6e\uff0c\u4e3b\u8981\u5173\u6ce8\u7684\u662f\u5e94\u7528\u7684UI\u6e32\u67d3<\/p>\n<p><strong>\u5b89\u88c5<\/strong><\/p>\n<p>\u4e3a\u4e86\u5feb\u901f\u5165\u95e8\uff0cNuxt.js\u56e2\u961f\u521b\u5efa\u4e86\u811a\u624b\u67b6\u5de5\u5177<code>create-nuxt-app<\/code><\/p>\n<pre><code class=\"language-bash\">\/\/ \u786e\u4fdd\u5b89\u88c5\u4e86npx\uff08npx\u5728NPM\u7248\u672c5.2.0\u9ed8\u8ba4\u5b89\u88c5\u4e86\uff09\nnpx create-nuxt-app &lt;\u9879\u76ee\u540d&gt;<\/code><\/pre>\n<p>\u5b83\u4f1a\u8ba9\u4f60\u8fdb\u884c\u4e00\u4e9b\u9009\u62e9\uff0c\u5982\u5728\u96c6\u6210\u7684\u670d\u52a1\u5668\u7aef\u6846\u67b6\u5982: Express\u3001Koa\u3001Hapi\u3001Feathers\u3001Micro\u3001Adonis (WIP)\uff1b\u9009\u62e9\u60a8\u559c\u6b22\u7684UI\u6846\u67b6: Bootstrap\u3001Vuetify\u3001Bulma\u3001Buefy\u7b49\u7b49<\/p>\n<p><strong>Hello World<\/strong><\/p>\n<p>Nuxt\u4f9d\u636e pages \u76ee\u5f55\u7ed3\u6784\u81ea\u52a8\u751f\u6210<code>vue-router<\/code>\u6a21\u5757\u7684\u8def\u7531\u914d\u7f6e<\/p>\n<pre><code class=\"language-html\">\/\/ .\/pages\/index.vue\n&lt;template&gt;\n  &lt;div&gt;\n    &lt;h1&gt;Hello world!&lt;\/h1&gt;\n    &lt;NLink to=&quot;\/about&quot;&gt;\n      About Page\n    &lt;\/NLink&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n<p><strong>\u597d\u5904<\/strong><\/p>\n<ul>\n<li>\u5b83\u7684\u4e3b\u8981\u8303\u56f4\u662fUI\u6e32\u67d3\uff0c\u540c\u65f6\u62bd\u8c61\u51fa\u5ba2\u6237\u7aef\/\u670d\u52a1\u5668\u5206\u5e03<\/li>\n<li>\u9759\u6001\u6e32\u67d3\u3001\u524d\u540e\u5206\u79bb<\/li>\n<li>\u81ea\u52a8\u4ee3\u7801\u5206\u5c42<\/li>\n<li>\u670d\u52a1\u3001\u6a21\u677f\u7686\u53ef\u914d\u7f6e<\/li>\n<li>\u9879\u76ee\u7ed3\u6784\u6e05\u6670<\/li>\n<li>\u7ec4\u4ef6\u4e0e\u9875\u9762\u65e0\u7f1d\u5207\u6362<\/li>\n<li>\u9ed8\u8ba4\u652f\u6301\u5f97ES6 \/ ES7<\/li>\n<li>\u652f\u6301\u5f00\u53d1\u70ed\u66f4\u65b0<\/li>\n<li>\u8def\u7531\u7ea7\u522b\u7684\u5f02\u6b65\u6570\u636e\u83b7\u53d6<\/li>\n<li>\u652f\u6301\u9759\u6001\u6587\u4ef6\u670d\u52a1<\/li>\n<li>\u6837\u5f0f\u9884\u5904\uff1aSass\uff0cLess\uff0cStylus\u7b49<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9<\/strong><\/p>\n<ul>\n<li>\u5468\u8fb9\u8d44\u6e90\u8f83\u5c11<\/li>\n<li>\u5f00\u53d1\u590d\u6742\u7684\u7ec4\u4ef6\u53ef\u80fd\u4f1a\u5f88\u9ebb\u70e6<\/li>\n<li>\u81ea\u5b9a\u4e49\u914d\u7f6e\u663e\u5f97\u5f88\u9ebb\u70e6<\/li>\n<li>\u5f88\u591a\u5177\u6709\u526f\u4f5c\u7528\u7684\u6570\u636e\u64cd\u4f5c<code>this.items[key]=value<\/code><\/li>\n<li>\u9ad8\u6d41\u91cf\u53ef\u80fd\u4f1a\u7ed9\u670d\u52a1\u5668\u5e26\u6765\u538b\u529b<\/li>\n<li>\u53ea\u80fd\u5728\u67d0\u4e9b\u6302\u94a9\u4e2d\u67e5\u8be2\u548c\u64cd\u4f5cDOM<\/li>\n<\/ul>\n<p><strong>\u6027\u80fd<\/strong><\/p>\n<p>Nuxt\u4e2d\u7684\u57fa\u672cHelloWorld\u5e94\u7528\u3002\u6bcf\u79d2\u80fd\u5904\u7406190.05\u4e2a\u8bf7\u6c42\u3002\u5e73\u5747\u4e00\u4e2a\u8bf7\u6c42\u65f6\u95f4\u4e3a52.619\u6beb\u79d2\u3002\u5728\u6b64\u5ea6\u91cf\u6807\u51c6\u4e0a\uff0cNuxt\u4e0e\u5176\u4ed6\u4e24\u4e2a\u6846\u67b6\u76f8\u6bd4\u8868\u73b0\u6700\u5dee<\/p>\n<p>Lighthouse\u6d4b\u8bd5\u62a5\u544a\u4e2dPreformance\u3001Accessibility\u3001SEO\u4e09\u9879\u4e2d\u5f97\u5206\u6700\u9ad8<\/p>\n<h2>Nest<\/h2>\n<p>Nest\u662f\u4e00\u4e2a\u6e10\u8fdb\u5f0fNode\u6846\u67b6\uff0c\u6df1\u53d7Angular\u7684\u542f\u53d1\u3002\u7528\u4e8e\u6784\u5efa\u9ad8\u6548\uff0c\u53ef\u6269\u5c55\u7684Node.js\u670d\u52a1\u5668\u7aef\u5e94\u7528\u7a0b\u5e8f\u7684\u6846\u67b6\u3002\u4f7f\u7528TypeScript\u6784\u5efa\uff0c\u4fdd\u7559\u4e0e\u7eafJS\u7684\u517c\u5bb9\u6027\uff0c\u96c6OOP\uff08\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff09\u3001FP\uff08\u51fd\u6570\u5f0f\u7f16\u7a0b\uff09\u3001FRP\uff08\u54cd\u5e94\u5f0f\u7f16\u7a0b\uff09\u4e00\u8eab\u3002\u670d\u52a1\u5f15\u64ce\u76d6\u9ed8\u8ba4\u4f7f\u7528Express\u4f46\u4e5f\u63d0\u4f9b\u4e0e\u5404\u79cd\u5176\u4ed6\u5e93\u7684\u517c\u5bb9\u6027\uff0c\u4f8b\u5982Fastify\uff0c\u5141\u8bb8\u8f7b\u677e\u4f7f\u7528\u53ef\u7528\u7684\u65e0\u6570\u7b2c\u4e09\u65b9\u63d2\u4ef6<\/p>\n<p><strong>\u5b89\u88c5<\/strong><\/p>\n<p>nest\u63d0\u4f9bcli\u4f7f\u7528\u8be5cli\u547d\u4ee4\u5b89\u88c5Nest\u5e76\u521b\u5efa\u65b0\u9879\u76ee\uff1a<\/p>\n<pre><code class=\"language-bash\">npm i @nestjs\/cli\nnest new project-name<\/code><\/pre>\n<p>\u6216\u8005\uff0c\u4f7f\u7528Git\u5b89\u88c5TypeScript\u542f\u52a8\u9879\u76ee\uff1a<\/p>\n<pre><code class=\"language-bash\">git clone https:\/\/github.com\/nestjs\/typescript-starter.git project\ncd project\nnpm install\nnpm run start<\/code><\/pre>\n<p><strong>Hello World<\/strong><\/p>\n<p>\u4f7f\u7528\u8be5npm cli\u547d\u4ee4\u521b\u5efa\u65b0\u9879\u76ee\u540e\uff0csrc\u76ee\u5f55\u4e0b\u4f1a\u51fa\u73b0\u51e0\u4e2a\u6838\u5fc3\u6587\u4ef6\uff0c<code>main.ts<\/code>\u662f\u6211\u4eec\u7684\u5165\u53e3<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u7136\u540e\u76d1\u542c3000\u7aef\u53e3\nimport { NestFactory } from &#039;@nestjs\/core&#039;;\nimport { ApplicationModule } from &#039;.\/app.module&#039;;\n\nasync function bootstrap() {\n  const app = await NestFactory.create(ApplicationModule);\n  await app.listen(3000);\n}\nbootstrap();\n\n\/\/ \u542f\u52a8\u8d77\u6765 \nnpm start<\/code><\/pre>\n<p><strong>\u597d\u5904<\/strong><\/p>\n<ul>\n<li>\u4f5c\u4e3a\u57fa\u4e8eTypeScript\u7684Web\u6846\u67b6\uff0c\u53ef\u4ee5\u8fdb\u884c\u4e25\u683c\u7684\u7c7b\u578b\u5b9a\u4e49<\/li>\n<li>\u81ea\u52a8\u751f\u6210Swagger\u6587\u6863<\/li>\n<li>Nest\u4e2d\u7684\u6587\u4ef6\u5939\u7ed3\u6784\u4e3b\u8981\u57fa\u4e8eAngular<\/li>\n<li>\u57fa\u4e8e\u6a21\u5757\u7684\u6846\u67b6\uff0c\u4ee3\u7801\u53ef\u590d\u7528<\/li>\n<li>\u9879\u76ee\u7ed3\u6784\u6e05\u6670\uff0c\u53ea\u9700\u8981\u5173\u6ce8\u4e1a\u52a1\u65e0\u9700\u5173\u6ce8\u67b6\u6784<\/li>\n<li>\u4f7f\u7528\u6700\u65b0\u7248\u672c\u7684TypeScript\uff0c\u610f\u5473\u7740JS\u7684\u578b\u7279\u6027\u57fa\u672c\u90fd\u53ef\u7528<\/li>\n<li>\u4e3a\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\u66f4\u5c11\u7684\u4e0a\u4e0b\u6587\u5207\u6362\u3002\u4eceAngular\u4ee3\u7801\u5230Nest\u7684\u8fc7\u6e21\u76f8\u5bf9\u5bb9\u6613<\/li>\n<li>\u4e0eAngular\u7c7b\u4f3c\uff0cNest\u4e5f\u6709\u4e00\u4e2a\u4e0d\u9519\u7684\u547d\u4ee4\u884c\u5de5\u5177<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9<\/strong><\/p>\n<ul>\n<li>\u7f3a\u4e4f\u6587\u6863\u3002\u8be5\u6846\u67b6\u4e0e\u5176\u4ed6\u6846\u67b6\u6709\u5f88\u597d\u7684\u96c6\u6210\uff0c\u4f46\u6587\u6863\u5f88\u5c11<\/li>\n<li>\u80cc\u540e\u6ca1\u6709\u5927\u578b\u4f01\u4e1a\u7684\u652f\u6301\u529b<\/li>\n<li>\u603b\u4f53\u800c\u8a00\uff0c\u4e0e\u5176\u4ed6\u6846\u67b6\u76f8\u6bd4\uff0cNest\u7684\u793e\u533a\u89c4\u6a21\u8f83\u5c0f<\/li>\n<\/ul>\n<p><strong>\u6027\u80fd<\/strong><\/p>\n<p>Nest\u4e2d\u7684\u57fa\u672cHelloWorld\u5e94\u7528\u3002\u6bcf\u79d2\u80fd\u5904\u7406928.18\u4e2a\u8bf7\u6c42\u3002\u6bcf\u4e2a\u8bf7\u6c42\u7684\u5e73\u5747\u65f6\u95f4\u4e3a10.774\u6beb\u79d2\u3002\u5728\u6b64\u6307\u6807\u4e0a\uff0cNest\u5728\u6211\u4eec\u6bd4\u8f83\u7684\u4e09\u4e2a\u6846\u67b6\u4e2d\u8868\u73b0\u6700\u4f73<\/p>\n<p>Lighthouse\u63d0\u4f9b\u7684\u62a5\u544a\u4e2d\uff0cNest\u5177\u6709\u975e\u5e38\u9ad8\u7684\u6027\u80fd,\u4f46\u662faccessibility, best practices, SEO\u5f97\u5206\u8f83\u4f4e<\/p>\n<p>Nest\u4e0d\u662f\u6700\u6d41\u884c\u7684\u6846\u67b6\u4f46\u503c\u5f97\u4e00\u8bd5\uff01<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>Next, Nuxt, Nest\u6bd4\u8f83\u5c31\u5230\u8fd9\u91cc Preformance\u3001Accessibility\u3001Best Practices\u3001SEO\u9009\u62e9\u4f60\u6700\u60f3\u8981\u7684\u90a3\u4e2a\u5427<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Next\u3001Nuxt\u548cNest\u8fd9\u4e09\u4e2a\u6846\u67b6\u90fd\u662f\u670d\u52a1\u5668\u7aef\u6e32\u67d3\uff0c\u5b83\u4eec\u5206\u522b\u4e0eReact\u3001Vue\u548cAngular(\u4e09\u4e2a\u76ee\u524d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[285,286],"class_list":["post-1036","post","type-post","status-publish","format-standard","hentry","category-node","tag-next","tag-nuxt"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1036"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1036\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}