NoteDeep

nextJs 执行next build (为了发布上线时) ,next build到底做了哪些事情,原理是什么?

Note: next.config.js is a regular Node.js module, not a JSON file. It gets used by the Next server and build phases(阶段), and not included in the browser build.
next.config.js是一个常规的nodejs module, 会被next server和build阶段使用

目前的一些解释:
Here we've a much node like experience.
We've .next directory always. That's we save stuff for SSR and other client side files. When we run npm run build it optimize those files for the production build.
You don't have any executable there. Our next module will take care of them. When you run next start it'll find that .next directory and start the app.
We need to write a lot on how next works. I'll do it soon.


MyDocument.getInitialProps is used to generate the HTML structure and it should not be a part of your app. It's only running in the server.


nextjs 导入本地模块时报错的问题
https://github.com/vercel/next.js/issues/20266

nextjs 什么时候用 static、server-side、client-side
static
  • The data required to render the page is available at build time ahead of a user’s request.
  • The data comes from a headless CMS.
  • The data can be publicly cached (not user-specific).
  • The page must be pre-rendered (for SEO) and be very fast — getStaticProps generates HTML and JSON files, both of which can be cached by a CDN for performance.
server-side
You should use getServerSideProps only if you need to pre-render a page whose data must be fetched at request time. Time to first byte (TTFB) will be slower than getStaticProps because the server must compute the result on every request, and the result cannot be cached by a CDN without extra configuration.
If you don’t need to pre-render the data, then you should consider fetching data on the client side
client-side
If your page contains frequently updating data, and you don’t need to pre-render the data, you can fetch the data on the client side. An example of this is user-specific data. Here’s how it works:
  • First, immediately show the page without data. Parts of the page can be pre-rendered using Static Generation. You can show loading states for missing data.
  • Then, fetch the data on the client side and display it when ready.
This approach works well for user dashboard pages, for example. Because a dashboard is a private, user-specific page, SEO is not relevant and the page doesn’t need to be pre-rendered. The data is frequently updated, which requires request-time data fetching.

评论列表

    nextJs 执行next build (为了发布上线时) ,next build到底做了哪些事情,原理是什么?