Skip to content
PluginStats

unplugin-preprocessor-directives weekly downloads statistics

By kejunmao (2 listings) · npm · Vite plugins

<img src="assets/logo.svg" alt="logo" width="100" height="100" align="right" />

View on npm Fresh · Oct 18, 2026

unplugin-preprocessor-directives has 2,822 recorded weekly downloads on npm, a decrease of 62.4% over the past 30 days, ranking #1257 of 2,322 tracked listings.

Weekly downloads
2,822
Official API · Oct 18, 2026
7-day growth
-40.1%
-1.9K weekly downloads
30-day growth
-62.4%
-4.7K weekly downloads
90-day growth
-36.7%
-1.6K weekly downloads
Rank
#1257
Among tracked npm listings

About unplugin-preprocessor-directives

<img src="assets/logo.svg" alt="logo" width="100" height="100" align="right" />

unplugin-preprocessor-directives

[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![github stars][github-stars-src]][github-stars-href] [![bundle][bundle-src]][bundle-href] [![License][license-src]][license-href] [![JSDocs][jsdocs-src]][jsdocs-href]

English | 简体中文

Install

npm i unplugin-preprocessor-directives

[!NOTE] This plugin should be placed before all other plugins in your configuration to ensure preprocessor directives are processed first.

<details> <summary>Vite</summary><br>
// vite.config.ts
import PreprocessorDirectives from 'unplugin-preprocessor-directives/vite'

export default defineConfig({
  plugins: [
    PreprocessorDirectives({ /* options */ }), // Should be the first plugin
  ],
})

Example: playground/

<br></details>

<details> <summary>Rollup</summary><br>
// rollup.config.js
import PreprocessorDirectives from 'unplugin-preprocessor-directives/rollup'

export default {
  plugins: [
    PreprocessorDirectives({ /* options */ }),
  ],
}

<br></details>

<details> <summary>Webpack</summary><br>
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-preprocessor-directives/webpack')({ /* options */ })
  ]
}

<br></details>

<details> <summary>Nuxt</summary><br>
// nuxt.config.js
export default defineNuxtConfig({
  modules: [
    ['unplugin-preprocessor-directives/nuxt', { /* options */ }],
  ],
})

This module works for both Nuxt 2 and Nuxt Vite

<br></details>

<details> <summary>Vue CLI</summary><br>
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-preprocessor-directives/webpack')({ /* options */ }),
    ],
  },
}

<br></details>

<details> <summary>esbuild</summary><br>
// esbuild.config.js
import { build } from 'esbuild'
import PreprocessorDirectives from 'unplugin-preprocessor-directives/esbuild'

build({
  plugins: [PreprocessorDirectives()],
})

<br></details>

<details> <summary>Rspack (⚠️ experimental)</summary><br>
// rspack.config.js
module.exports = {
  plugins: [
    require('unplugin-preprocessor-directives/rspack')({ /* options */ }),
  ],
}

<br></details>

Usage

Defining symbols

You use the following two preprocessor directives to define or undefine symbols for conditional compilation:

  • #define: Define a symbol.
  • #undef: Undefine a symbol.

You use #define to define a symbol. When you use the symbol as the expression that's passed to the #if directive, the expression will evaluate to true, as the following example shows:

// #define VERBOSE

// #if VERBOSE
console.log('Verbose output version')
// #endif
Conditional compilation
  • #if: Opens a conditional compilation, where code is compiled only if the specified symbol is defined and evaluated to true.
  • #elif: Closes the preceding conditional compilation and opens a new conditional compilation based on if the specified symbol is defined and evaluated to true.
  • #else: Closes the preceding conditional compilation and opens a new conditional compilation if the previous specified symbol isn't defined or evaluated to false.
  • #endif: Closes the preceding conditional compilation.

[!NOTE] By default, use vite's loadEnv function to load environment variables based on process.env.NODE_ENV and compile symbols as conditions.

// src/index.ts

// #if DEV
console.log('Debug version')
// #endif

// #if !MYTEST
console.log('MYTEST is not defined or false')
// #endif

You can use the operators == (equality) and != (inequality) to test for the bool values true or false. true means the symbol is defined. The statement #if DEBUG has the same meaning as #if (DEBUG == true). You can use the && (and), || (or), and ! (not) operators to evaluate whether multiple symbols have been defined. You can also group symbols and operators with parentheses.

class MyClass {
  constructor() {
    // #if (DEBUG && MYTEST)
    console.log('DEBUG and MYTEST are defined')
    // #elif (DEBUG==false && !MYTEST)
    console.log('DEBUG and MYTEST are not defined')
    // #endif
  }
}
Error and warning and info messages

You instruct the compiler to generate user-defined compiler errors and warnings and informational messages.

  • #error: Generates an error, but does not terminate compilation.
  • #warning: Generates a warning.
  • #info: Generates an informational message.
// #error this is an error message
// #warning this is a warning message
// #info this is an info message

Of course, it can also be combined with conditional compilation:

// #if DEBUG
// #info Debug mode is on
// #endif
// #if !DEBUG
// #info Debug mode is off
// #endif
#include directive

You can use the #include directive to include the contents of other files into the current file. The included files are also processed by the preprocessor.

[!WARNING] The #include directive is a compile-time text replacement tool, primarily intended for these scenarios:

  • Including different configuration code snippets in different environments
  • Combining with conditional compilation to include different code based on compilation conditions
  • Sharing code snippets that require preprocessing

It cannot and should not replace:

  • JavaScript/TypeScript import or require - for modularization and dependency management
  • CSS @import - for stylesheet modularization
  • HTML template systems or component systems

If you simply want to modularize your code, please use the language's native module system. Only use #include when you need compile-time processing and conditional inclusion.…

Description from the npm listing.

  • unplugin
  • vite
  • webpack
  • rollup
  • rspack
  • transform
  • vite-plugin
  • webpack-plugin
  • rollup-plugin
  • esbuild-plugin
  • rspack-plugin
  • nuxt-plugin
  • directives
  • preprocessor

README badge

Show your rank in a README or on your website. The badge updates automatically.

Charts

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

Adoption over time

unplugin-preprocessor-directives weekly downloads on npm, last 90 days: 2,822 weekly downloads as of Oct 18, 2026, -36.7% over 90 days.unplugin-preprocessor-directivesWeekly downloads on npm · Last 90 days2,822downloads / week-36.7% over 90 days02K4K6K8K10KJul 20Aug 4Aug 19Sep 3Sep 18Oct 3Oct 18downloads / weekobservedarchived (Internet Archive)no observationsJul 22, 2026 – Oct 18, 2026 · 89 observations · Updated Oc…pluginstats.com
unplugin-preprocessor-directives weekly downloads on npm, last 90 days: 2,822 weekly downloads as of Oct 18, 2026, -36.7% over 90 days.

7/30/90-day growth

unplugin-preprocessor-directives weekly downloads growth on npm: -40.1% over 7 days, -62.4% over 30 days, -36.7% over 90 days.unplugin-preprocessor-directivesWeekly downloads growth on npm2,822downloads / week now7-day growth-1,890 weekly downloads-40.1%30-day growth-4,686 weekly downloads-62.4%90-day growth-1,639 weekly downloads-36.7%Growth vs. nearest observation to each baseline date · Updated Oct 18, 2026pluginstats.com
unplugin-preprocessor-directives weekly downloads growth on npm: -40.1% over 7 days, -62.4% over 30 days, -36.7% over 90 days.

Ranking history

unplugin-preprocessor-directives npm ranking history: currently #1257 (by weekly downloads).unplugin-preprocessor-directivesnpm ranking · by weekly downloads · Last 90 days#1257current rank#1220#1225#1230#1235#1240#1245#1250#1255#1260Jul 22Aug 6Aug 21Sep 5Sep 20Oct 5Oct 20rankOct 18, 2026 – Oct 20, 2026 · 3 observations · Updated Oct 18, 2026pluginstats.com
unplugin-preprocessor-directives npm ranking history: currently #1257 (by weekly downloads).

Listing placement

All npm2,320 listings · 116 pages · 1,162 shown · page 63, #20 (overall #1,260)
All npm: every listing in weekly downloads order

Listing placement

Vite plugins253 listings · 13 pages · page 12, #17 (overall #237)
Vite plugins: every listing in weekly downloads order

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.

Each band is one page of 20. Weekly downloads on a linear 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.

Recent observations

Full history (122)
Recent weekly downloads observations for unplugin-preprocessor-directives
Date (UTC)Weekly downloadsChange vs. previous
2,822+165
2,657-338
2,995+373
2,622-993
3,615-1K
4,6420
4,642-70
4,712+36
4,676-23
4,699+213
4,486-396
4,882-17
4,899-986
5,885—

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/unplugin-preprocessor-directives. First seen Oct 16, 2026; last successful collection Oct 20, 2026. See the methodology.