# nuxt-define

> One utility function for module authors to define compiler constants for all builders supported by Nuxt.

Latest version **1.0.0** (published 2025-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install nuxt-define
pnpm add nuxt-define
yarn add nuxt-define
bun add nuxt-define
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2025-06-06 |
| First published | 2025-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bobbie Goede |
| Maintainers | bobbiegoede |
| Keywords | nuxt, module |

## Links

- npm: https://www.npmjs.com/package/nuxt-define
- Funding: https://github.com/sponsors/bobbiegoede
- npm.io page: https://npm.io/package/nuxt-define

## Recent versions

- 1.0.0 (latest) — 2025-06-06
- 0.0.2 — 2025-06-06
- 0.0.1 — 2025-06-06

## README

[![](https://img.shields.io/npm/v/nuxt-define/latest.svg?style=flat&label=npm&colorA=18181B)](https://npmjs.com/package/nuxt-define)
[![](https://img.shields.io/npm/dm/nuxt-define?style=flat&colorA=18181B&color=blue)](https://npmjs.com/package/nuxt-define)

# Nuxt Define

One utility function for module authors to define compiler constants for all builders supported by Nuxt.

Supported builders:
* Vite
* Webpack
* Rspack

## Installation

```bash
npm i nuxt-define
```

## Usage

```ts
// src/module.ts
import { addDefinePlugin } from 'nuxt-define'

export default defineNuxtModule({
  setup() {
    addDefinePlugin({
      '__MY_CONSTANT__': JSON.stringify('myValue'),
      '__SOME_FEATURE_FLAG__': JSON.stringify(false),
    })
  }
})
```

```ts
// src/runtime/foo.ts
export function foo() {
  console.log(__MY_CONSTANT__) // 'myValue'

  if (__SOME_FEATURE_FLAG__) {
    // expensive computation
    // omitted from final build if compiler constant is false
  } 
}

```

## Why?

Nuxt supports multiple builders, and each builder has its own way of defining constants. This module abstracts that complexity and provides a unified API to define compiler constants that work across all supported builders.

An added bonus is that you do not need to explicitly add these builders as dev dependencies, keeping your Github notifications free of renovate PR noise.

## Sponsors

<p align="center">
  <a href="https://raw.githubusercontent.com/bobbiegoede/static/main/sponsors.svg">
    <img src="https://raw.githubusercontent.com/bobbiegoede/static/main/sponsors.svg" />
  </a>
</p>

---
_Source: https://npm.io/package/nuxt-define · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
