

























We're laying the foundation for the future of Next.js with 12.2:
next/image: Including a new next/future/image component.Update today by running npm i next@latest.
We're excited to announce Middleware is now stable in 12.2 and has an improved API based on feedback from users.
Middleware allows you to run code before a request is completed. Based on the incoming request, you can modify the response by rewriting, redirecting, adding headers, or setting cookies.
To update to the newest API changes for Middleware, please see the migration guide.
Try Middleware for free on Vercel or when self-hosting using next start.
On-Demand Incremental Static Regeneration (ISR) allows you to update the content on your site without needing to redeploy. This makes it easy to update your site immediately when data changes in your headless CMS or commerce platform. This was one of the most requested features from the community and we're excited it is now stable.
Incremental Static Regeneration works for any providers supporting the Next.js Build API (next build). When deployed to Vercel, on-demand revalidation propagates globally in ~300ms when pushing pages to the edge.
For more information, check out the documentation or view our demo to see on-demand revalidation in action.
Next.js now also supports using the Edge Runtime for API Routes. The Edge Runtime is a lighter-weight runtime than Node.js providing fast startups for low latency. In addition, Edge API Routes support streaming responses from the server.
You can set the runtime for an API Route in the config, specifying either nodejs (default) or experimental-edge:
Because the Edge Runtime is lightweight, it has limitations to accommodate fast startup — for example, it does not support Node.js-specific APIs like fs. Therefore, the default runtime for API Routes remains nodejs.
For more information, check out the documentation.
Next.js now supports using the Edge Runtime for server rendering.
As mentioned above, the Edge Runtime is a lighter-weight runtime than Node.js providing fast startups for low latency. When used with React 18, it enables streaming server-rendering for Pages.
Next.js uses Node.js as the default runtime for server-side rendering pages. Starting with 12.2, if you are using React 18 you can opt into using the Edge Runtime.
You can set the runtime globally in next.config.js, specifying either nodejs or experimental-edge:
Changing the default page runtime affects all pages, including SSR streaming and Server Components features. You can also override this default on a per-page basis, by exporting a runtime config:
You can detect which runtime you're using by looking at the process.env.NEXT_RUNTIME Environment Variable during runtime, and examining the options.nextRuntime variable during webpack compilation.
For more information, check out the documentation.
next/imagenext/future/image component (Experimental)We've heard your feedback on the current Image component and are excited to share an early preview of the new next/image. This new and improved image component requires less client-side JavaScript and simplifies how you style images:
<img> without <div> or <span> wrappersstyle proplayout, objectFit, and objectPosition props in favor of style or classNameIntersectionObserver implementation in favor of native lazy loadingloader config in favor of loader propfill mode (yet) so width & height props are requiredThis improves performance because native loading="lazy" doesn't need to wait for React hydration and client-side JavaScript.
For more information, check out the documentation.
next/image now supports an experimental configuration option remotePatterns that allows you to specify wildcards for remote images when using the built-in Image Optimization API. This allows for more powerful matching beyond the existing images.domains configuration, which only performs exact matches on the domain name.
For more information, check out the documentation.
The zero-config Image Optimization API prevents the use of next export since it requires a server to optimize images on-demand as they're requested. Until today, users targeting next export needed to configure the loader to use a 3rd party Image Optimization provider, but there was no clear solution if there was no provider available. Starting today, next export users can disable Image Optimization for all instances of next/image with a new configuration property:
The Next.js Compiler uses SWC to transform and minify your JavaScript code for production. SWC was introduced in Next.js 12.0 to improve both local development and build performance.
You can now add plugins (written in WebAssembly) to customize the SWC transformation behavior during compilation:
For more information, check out the documentation.
styled-components and emotion with a smoother upgrade experience and no breaking changes.next/head now supports React 18.@emotion/babel-plugin are now supported, and unless you are using importMap, it can be removed. For more information, check out the documentation.styled-components transform in the Next.js Compiler by allowing customization of the default options, including the cssProp option. For more information, check out the documentation.next/image and next/link can properly be imported.next/link no longer requires manually adding <a> as a child. You can now opt into this behavior in a backward-compatible way.browsersList. You can opt-into this behavior by setting browsersListForSwc: true and legacyBrowsers: false in the experimental option of next.config.js.@swc/helpers optimizations prevent duplication across bundles, reducing bundle size by around 2KB in a minimal configuration, and more on larger appspnpm, which allows us to remove duplicate packages while creating the pre-compiled versions that we use. This leads to a reduction in install size of 14MB.outputStandalone: true config to output: 'standalone'. This config reduces deployment sizes drastically by only including necessary files/assets, including removing the need for installing all of node_modules in the built deployment package. This config can be seen in action in our with-docker example.In case you missed it, last month we announced the Layouts RFC – the biggest update to Next.js since it was introduced in 2016 including:
For more information, check out the RFC or provide feedback.
Next.js is the result of the combined work of over 2,000 individual developers, industry partners like Google Chrome and Meta, and our core team at Vercel.
This release was brought to you by the contributions of: @huozhi, @ijjk, @kwonoj, @ViolanteCodes, @akrabdev, @timneutkens, @jpveilleux, @stigkj, @jgoping, @oof2win2, @Brooooooklyn, @CGamesPlay, @lfades, @molebox, @steven-tey, @SukkaW, @Kikobeats, @balazsorban44, @erikbrinkman, @therealmarzouq, @remcohaszing, @perkinsjr, @shuding, @hanneslund, @housseindjirdeh, @RobertKeyser, @styfle, @htunnicliff, @lukeshumard, @sagnik3, @pixelass, @JoshuaKGoldberg, @rishabhpoddar, @nguyenyou, @kdy1, @sidwebworks, @gnoff, @gaspar09, @feugy, @mfix-stripe, @javivelasco, @Chastrlove, @goncharov-vlad, @NaveenDA, @Firfi, @idkwhojamesis, @FLCN-16, @icyJoseph, @ElijahPepe, @elskwid, @irvile, @Munawwar, @ykolbin, @hulufei, @baruchadi, @imadatyatalah, @await-ovo, @menosprezzi, @gazs, @Exortions, @rubens-lopes, @woochul2, @stefee, @stmtk1, @jlarmstrongiv, @MaedahBatool, @jameshfisher, @fabienheureux, @TxHawks, @mattbrandlysonos, @iggyzap, @src200, @AkifumiSato, @hermanskurichin, @kamilogorek, @ben-xD, @dawsonbooth, @Josehower, @crutchcorn, @ericmatthys, @CharlesStover, @charlypoly, @apmatthews, @naingaungphyo, @alexandrutasica, @stefanprobst, @dc7290, @DilwoarH, @tommarshall, @stanhong, @leerob, @appsbytom, @sshyam-gupta, @saulloalmeida, @indicozy, @ArianHamdi, @Clariity, @sebastianbenz, @7iomka, @gr-qft, @Schniz, @dgagn, @sokra, @okbel, @tbvjaos510, @dmvjs, @PepijnSenders, @JohnPhamous, @kyliau, @eric-burel, @alabhyajindal, @jsjoeio, @vorcigernix, @clearlyTHUYDOAN, @splatterxl, @manovotny, @maxproske, @nvh95, @frankievalentine, @nuta, @bagpyp, @dfelsie, @qqpann, @atcastle, @jsimonrichard, @mass2527, @ekamkohli, @Yuddomack, @tonyspiro, @saurabhmehta1601, @banner4422, @falsepopsky, @jantimon, @henriqueholtz, @ilfa, @matteobruni, @ryscheng, @hoonoh, @ForsakenHarmony, @william-keller, @AleksaC, @Miikis, @zakiego, @radunemerenco, @AliYusuf95, and @dominiksipowicz.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。