Skip to content
PluginStats

babel-plugin-preval weekly downloads statistics

By kentcdodds (2 listings) · npm · Babel plugins

Pre-evaluate code at build-time

View on npm Fresh · Oct 17, 2026

babel-plugin-preval has 28,941 recorded weekly downloads on npm, a decrease of 53.2% over the past 30 days.

It ranks #668 of 2,256 tracked npm listings by weekly downloads.

Over 90 days, weekly downloads changed by -62.4%.

PluginStats has 121 daily observations since Jun 19, 2026; the latest is from Oct 17, 2026.

Weekly downloads
28,941
Official API · Oct 17, 2026
7-day growth
-50.3%
-29.3K weekly downloads
30-day growth
-53.2%
-32.9K weekly downloads
90-day growth
-62.4%
-48K weekly downloads
Rank
#668
Among tracked npm listings

About babel-plugin-preval

babel-plugin-preval

Pre-evaluate code at build-time

[![Build Status][build-badge]][build] [![Code Coverage][coverage-badge]][coverage] [![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends] [![MIT License][license-badge]][license]

[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc] [![Babel Macro][macros-badge]][babel-plugin-macros] [![Examples][examples-badge]][examples]

The problem

You need to do some dynamic stuff, but don't want to do it at runtime. Or maybe you want to do stuff like read the filesystem to get a list of files and you can't do that in the browser.

This solution

This allows you to specify some code that runs in Node and whatever you module.exports in there will be swapped. For example:

Or, more interestingly:

There's also preval.require('./something') and import x from /* preval */ './something' (which can both take some arguments) or add // @preval comment at the top of a file.

See more below.

Table of Contents

• Installation • Usage • Template Tag • import comment • preval.require • preval file comment (// @preval) • Exporting a function • Configure with Babel • Via .babelrc (Recommended) • Via CLI • Via Node API • Use with babel-plugin-macros • Examples • Notes • FAQ • How is this different from prepack? • How is this different from webpack loaders? • Inspiration • Related Projects • Other Solutions • Issues • 🐛 Bugs • 💡 Feature Requests • Contributors ✨ • LICENSE

Installation

This module is distributed via [npm][npm] which is bundled with [node][node] and should be installed as one of your project's devDependencies:

Usage

Important notes:

1. All code run by preval is _not_ run in a sandboxed environment 2. All code _must_ run synchronously. 3. Code that is run by preval is not transpiled so it must run natively in the version of node you're running. (cannot use es modules).

You may like to watch this YouTube video to get an idea of what preval is and how it can be used.

Template Tag

Before:

After (assuming greeting.txt contains the text: "Hello world!"):

preval can also handle _some_ simple dynamic values as well:

Before:

After (assuming ./name-splitter is a function that splits a name into first/last):

import comment

Before:

After (depending on what ./get-list-of-files does, it might be something like):

You can also provide arguments which themselves are prevaled!

Before:

After (assuming ./get-list-of-files accepts an argument limiting how many files are retrieved:

preval.require

Before:

After:

And you can provide _some_ simple dynamic arguments as well:

Before:

After:

preval file comment (// @preval)

Using the preval file comment will update a whole file to be evaluated down to an export.

Whereas the above usages (assignment/import/require) will only preval the scope of the assignment or file being imported.

Before:

After:

Exporting a function

If you export a function from a module that you're prevaling (whether using preval.require or the import comment), then that function will be called and whatever is returned will be the prevaled value.

It's important to know this if you want to have the prevaled value itself be a function:

Example:

Usage of preval:

Generated code:

Configure with Babel

Via .babelrc (Recommended)

.babelrc

Via CLI

Via Node API

Use with babel-plugin-macros

Once you've configured babel-plugin-macros you can import/require the preval macro at babel-plugin-preval/macro. For example:

You could also use [preval.macro][preval.macro] if you'd prefer to type less 😀

Examples

• Mastodon saved 40kb (gzipped) using babel-plugin-preval • glamorous-website uses [preval.macro][preval.macro] to determine Algolia options based on process.env.LOCALE. It also uses [preval.macro][preval.macro] to load an svg file as a string, base64 encode it, and use it as a background-url for an input element. • Generate documentation for React components • Serverless with webpack build serverless functions using webpack and Babel for development and production with preval to replace (possible sensible) content in code. • Read files at build time (video)

Notes

If you use babel-plugin-transform-decorators-legacy, there is a conflict because both plugins must be placed at the top

Wrong:

Ok:

FAQ

How is this different from prepack?

[prepack][prepack] is intended to be run on your final bundle after you've run your webpack/etc magic on it. It does a TON of stuff, but the idea is that your code should work with or without prepack.

babel-plugin-preval is intended to let you write code that would _not_ work otherwise. Doing things like reading something from the file system are not possible in the browser (or with prepack), but preval enables you to do this.

How is this different from webpack loaders?

This plugin was inspired by webpack's [val-loader][val-loader]. The benefit of using this over that loader (or any other loader) is that it integrates with your existing babel pipeline. This is especially useful for the server where you're probably not bundling your code with [webpack][webpack], but you may be using babel. (If you're not using either, configuring babel for this would be easier than configuring webpack for val-loader).

In addition, you can implement pretty much any webpack loader using babel-plugin-preval.

If you want to learn more, check webpack documentations about [loaders][webpack-loaders].

Inspiration

I needed something like this for the glamorous website. I live-streamed developing the whole thing. If you're interested you can find the recording on my youtube channel (note, screen only recording, no audio).

I was inspired by the [val-loader][val-loader] from webpack.

Related Projects

• [preval.macro][preval.macro] - nicer integration with babel-plugin-macros • define_macro-loader - Integrate preval with C-Like macros, thus, increasing preval use cases.

Other Solutions…

Description from the npm listing.

  • babel
  • babel-plugin
  • eval
  • precompile
  • babel-plugin-macros

Where babel-plugin-preval sits in the listing

Each band is one page of 20. Weekly downloads on a log scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.

All npm2,256 listings · 113 pages · page 34, #8 (overall #668)
All npm: every listing in weekly downloads order
PNG SVG
Babel plugins251 listings · 13 pages · page 13, #8 (overall #248)
Babel plugins: every listing in weekly downloads order
PNG SVG

Charts

Images: 30d · 1y · all time · 1600×900 dark

Adoption over time

babel-plugin-preval weekly downloads on npm, last 90 days: 28,941 weekly downloads as of Oct 17, 2026, -62.4% over 90 days.babel-plugin-prevalWeekly downloads on npm · Last 90 days28,941downloads / week-62.4% over 90 days20K30K40K50K60K70K80K90KJul 19Aug 3Aug 18Sep 2Sep 17Oct 2Oct 17downloads / weekobservedarchived (Internet Archive)no observationsJul 21, 2026 – Oct 17, 2026 · 89 observations · Updated Oc…pluginstats.com
babel-plugin-preval weekly downloads on npm, last 90 days: 28,941 weekly downloads as of Oct 17, 2026, -62.4% over 90 days.
PNG SVG

7/30/90-day growth

babel-plugin-preval weekly downloads growth on npm: -50.3% over 7 days, -53.2% over 30 days, -62.4% over 90 days.babel-plugin-prevalWeekly downloads growth on npm28,941downloads / week now7-day growth-29,259 weekly downloads-50.3%30-day growth-32,940 weekly downloads-53.2%90-day growth-47,962 weekly downloads-62.4%Growth vs. nearest observation to each baseline date · Updated Oct 17, 2026pluginstats.com
babel-plugin-preval weekly downloads growth on npm: -50.3% over 7 days, -53.2% over 30 days, -62.4% over 90 days.
PNG SVG

Ranking history

babel-plugin-preval npm ranking history: currently #668 (by weekly downloads).babel-plugin-prevalnpm ranking · by weekly downloads · Last 90 days#668current rank#666#667#668#669#670Jul 21Aug 5Aug 20Sep 4Sep 19Oct 4Oct 19rankOct 18, 2026 – Oct 19, 2026 · 2 observations · Updated Oct 17, 2026pluginstats.com
babel-plugin-preval npm ranking history: currently #668 (by weekly downloads).
PNG SVG

Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.

Recent observations

Full history (121)
Recent weekly downloads observations for babel-plugin-preval
Date (UTC)Weekly downloadsChange vs. previous
28,941-5.9K
34,884+955
33,929-12.8K
46,736-12.9K
59,6850
59,685-5
59,690+1.5K
58,200+1.6K
56,559+1.6K
54,948+1.5K
53,451-1.6K
55,036-12.6K
67,677-1K
68,697—

Similar npm Babel plugins plugins

Data source

Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.

Listing: https://www.npmjs.com/package/babel-plugin-preval. First seen Oct 16, 2026; last successful collection Oct 19, 2026. See the methodology.