More Premium Hugo Themes Premium Nextjs Themes

Next Plugin Preval

Pre-evaluate async functions during builds and import them like JSON

Next Plugin Preval

Pre-evaluate async functions during builds and import them like JSON

Author Avatar Theme by ricokahler
Github Stars Github Stars: 255
Last Commit Last Commit: Mar 1, 2025 -
First Commit Created: Dec 18, 2023 -
Next Plugin Preval screenshot

Overview:

The next-plugin-preval is a plugin for the Next.js framework that allows for the pre-evaluation of async functions at build time and import them like JSON. It provides a solution for use cases where static data is required across multiple pages, static data for API routes, and de-duped and code split data. The plugin offers zero runtime, meaning that the pre-evaluated files are not sent to the browser, only their outputted JSON. However, it should be noted that once the data is generated during the initial build, it cannot be changed.

Features:

  • Pre-evaluate async functions at build time and import them like JSON.
  • Support for site-wide data that is required across multiple pages.
  • Support for static data in API routes to speed up response times and offload work from the database.
  • Leveraging bundler optimizations for importing static assets, including code splitting and de-duping.
  • Zero runtime: Only the outputted JSON is sent to the browser.
  • Ability to make preview mode work with a workaround by extracting the data fetching function and conditionally calling it based on preview mode.

Installation:

To install next-plugin-preval, either use the “Install” command or add it to your “next.config.js” file.

Summary:

The next-plugin-preval is a powerful plugin for the Next.js framework that allows for the pre-evaluation of async functions at build time and importing them like JSON. It provides solutions for handling static data across multiple pages, in API routes, and allows for bundler optimizations such as code splitting and de-duping. However, it should be noted that the pre-evaluated data cannot be changed once it is generated during the initial build.