Next.js 12.1 正式发布,企业级 Web 应用框架

栏目: 软件资讯 · 发布时间: 4年前

内容简介:Next.js 12.1 已正式发布。 新特性概览 按需使用的 ISR (Beta):支持即时使用getStaticProps重新验证页面 扩展对 SWC 的支持:引入styled-components和 Relay 等功能 引入next/jest插件:使用 SWC 实现零配置支持...

Next.js 12.1 已正式发布。

新特性概览

按需使用的 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.js for flags that enable Next.js compiler transforms

优化自托管功能

Next.js 现在支持自动创建standalone文件夹,该文件夹仅复制生产部署所需的文件。这使得自托管 Next.js 应用程序的Docker 映像缩小了约 80% 。

详情查看 release note。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Masterminds of Programming

Masterminds of Programming

Federico Biancuzzi、Chromatic / O'Reilly Media / 2009-03-27 / USD 39.99

Description Masterminds of Programming features exclusive interviews with the creators of several historic and highly influential programming languages. Think along with Adin D. Falkoff (APL), Jame......一起来看看 《Masterminds of Programming》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具