Skip to content
PluginStats

unplugin-preprocessor-directives weekly downloads statistics

By kejunmao (2 listings) · npm · Webpack plugins

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

View on npm Fresh · Dec 6, 2026

unplugin-preprocessor-directives has 7,234 recorded weekly downloads on npm, an increase of 21.7% over the past 30 days, ranking #1396 of 3,247 tracked listings.

Weekly downloads
7,234
Official API · Dec 5, 2026
7-day growth
+46.9%
+2.3K weekly downloads
30-day growth
+21.7%
+1.3K weekly downloads
90-day growth
+77.3%
+3.2K weekly downloads
Rank
#1396
▲ 105 in 7 days

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: 7,234 weekly downloads as of Dec 5, 2026, +77.3% over 90 days.unplugin-preprocessor-directivesWeekly downloads on npm · Last 90 days7,234downloads / week+77.3% over 90 days02K4K6K8K10KSep 6Sep 21Oct 6Oct 21Nov 5Nov 20Dec 5downloads / weekobservedarchived (Internet Archive)no observationsSep 7, 2026 – Dec 5, 2026 · 90 observations · Updated Dec …pluginstats.com
unplugin-preprocessor-directives weekly downloads on npm, last 90 days: 7,234 weekly downloads as of Dec 5, 2026, +77.3% over 90 days.

7/30/90-day growth

unplugin-preprocessor-directives weekly downloads growth on npm: +46.9% over 7 days, +21.7% over 30 days, +77.3% over 90 days.unplugin-preprocessor-directivesWeekly downloads growth on npm7,234downloads / week now7-day growth+2,308 weekly downloads+46.9%30-day growth+1,292 weekly downloads+21.7%90-day growth+3,155 weekly downloads+77.3%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
unplugin-preprocessor-directives weekly downloads growth on npm: +46.9% over 7 days, +21.7% over 30 days, +77.3% over 90 days.

Ranking history

unplugin-preprocessor-directives npm ranking history: currently #1396 (by weekly downloads).unplugin-preprocessor-directivesnpm ranking · by weekly downloads · Last 90 days#1396current rank#1150#1200#1250#1300#1350#1400#1450#1500#1550Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 18, 2026 – Dec 6, 2026 · 44 observations · Updated Dec 5, 2026pluginstats.com
unplugin-preprocessor-directives npm ranking history: currently #1396 (by weekly downloads).

Listing placement

All npm3,247 listings · 163 pages · 1,083 shown · page 70, #16 (overall #1,396)
All npm: every listing in weekly downloads order

Listing placement

Webpack plugins349 listings · 18 pages · page 2, #17 (overall #37)
Webpack 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 (170)
Recent weekly downloads observations for unplugin-preprocessor-directives
Date (UTC)Weekly downloadsChange vs. previous
7,234+219
7,015+665
6,350+434
5,916+123
5,793+772
5,021+34
4,987+61
4,926-172
5,098-587
5,685-153
5,838+133
5,705+36
5,669+101
5,568—

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 Dec 6, 2026. See the methodology.