内容简介:Next.js 12.1 已正式发布。 新特性概览 按需使用的 ISR (Beta):支持即时使用getStaticProps重新验证页面 扩展对 SWC 的支持:引入styled-components和 Relay 等功能 引入next/jest插件:使用 SWC 实现零配置支持...
Next.js 12.1 已正式发布。
新特性概览
- 按需使用的 ISR (Beta):支持即时使用
getStaticProps重新验证页面 - 扩展对 SWC 的支持:引入
styled-components和 Relay 等功能 - 引入
next/jest插件:使用 SWC 实现零配置支持 Jest - 通过 SWC (RC) 提供更快的压缩:比 Terser 快 7 倍的压缩速度
- 优化自托管功能:减小 Docker 镜像体积约 80%
- React 18 & Server Components (Alpha):优化稳定性和支持情况
按需使用的 ISR (Beta)
ISR 是 Next.js 9.5 引入的功能,本次的更新提供了按需使用的特性,开发者可按需手动清除特定页面的 Next.js 缓存。
// pages/api/revalidate.js
export default async function handler(req, res) {
// Check for secret to confirm this is a valid request
if (req.query.secret !== process.env.MY_SECRET_TOKEN) {
return res.status(401).json({ message: 'Invalid token' })
}
try {
await res.unstable_revalidate('/path-to-revalidate')
return res.json({ revalidated: true })
} catch (err) {
// If there was an error, Next.js will continue
// to show the last successfully generated page
return res.status(500).send('Error revalidating')
}
}
零配置 Jest 插件
Next.js 现已支持自动配置 Jest,使用基于 Rust 的 Next.js 编译器来转换文件,包括:
- 自动模拟样式表(
.css,.module.css和.scss变体),以及图像导入 - 将
.env加载到process.env - 忽略测试解析和转换的
node_modules - 忽略测试解析的
.next - Loading
next.config.jsfor flags that enable Next.js compiler transforms
优化自托管功能
Next.js 现在支持自动创建standalone文件夹,该文件夹仅复制生产部署所需的文件。这使得自托管 Next.js 应用程序的Docker 映像缩小了约 80% 。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Python for Data Analysis
Wes McKinney / O'Reilly Media / 2012-11-1 / USD 39.99
Finding great data analysts is difficult. Despite the explosive growth of data in industries ranging from manufacturing and retail to high technology, finance, and healthcare, learning and accessing d......一起来看看 《Python for Data Analysis》 这本书的介绍吧!