教程 > next.js 中文教程 > 阅读:384

next.js cli 命令行——迹忆客-ag捕鱼王app官网

next.js 提供了 cli 命令行 帮助我们启动、构建和导出(export)应用程序。它可以使用npx调用,该npx从5.2开始。

命令行 cli 帮助

要列出所有可用的 cli 命令,请在项目目录中运行以下命令:

$ npx next -h

npx next help

生产准备构建

$ npx next build
info  - loaded env from /workspace/node/nextjs/.env.local
creating an optimized production build
compiled successfully.
automatically optimizing pages
page                                                           size     first load js
  ? /                                                          2.25 kb        60.3 kb
    /_app                                                      288 b          58.1 kb
         /404                                                       3.25 kb   61.3 kb
  ? /api/user
  ? /posts/[id]                                                312 b          61.6 kb
      /posts/one
      /posts/two
  ? /posts/env                                                 2.71 kb        60.8 kb
  ? /posts/first                                               374 b          61.7 kb
  first load js shared by all                                  58.1 kb
    static/pages/_app.js                                       288 b
    chunks/ab55cb957ceed242a750c37a082143fb9d2f0cdf.a1a019.js  10.5 kb
    chunks/framework.c6faae.js                                 40 kb
    runtime/main.60464f.js                                     6.54 kb
    runtime/webpack.c21266.js                                  746 b
    css/9706b5b8ed8e82c0fba0.css                               175 b
?  (server)  server-side renders at runtime (uses getinitialprops or getserversideprops)
          (static)  automatically rendered as static html (uses no initial props)
?  (ssg)     automatically generated as static html   json (uses getstaticprops)

构建并启动开发服务器

使用以下命令。

$ npx next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - loaded env from /workspace/node/nextjs/.env.local
event - compiled client and server successfully in 443 ms (124 modules)

启动生产服务器

使用以下命令。

$ npx next start
info  - loaded env from /workspace/node/nextjs/.env.local
ready - started server on http://localhost:3000

查看笔记

扫码一下
查看教程更方便
网站地图