{"library":"nuxt-define","title":"Nuxt Compiler Constants Utility","description":"nuxt-define is a utility package designed for Nuxt module authors to uniformly define compiler constants across all supported Nuxt builders, including Vite, Webpack, and Rspack. It abstracts away the builder-specific mechanisms for constant definition, providing a single `addDefinePlugin` function. This allows module developers to avoid adding builder-specific dev dependencies, reducing dependency noise and ensuring consistent behavior regardless of the underlying bundler chosen by the Nuxt project. The current stable version is 1.0.0, suggesting a mature initial release. As a utility, its release cadence is likely tied to Nuxt ecosystem updates or bug fixes, rather than a strict schedule. Its key differentiator is simplifying cross-builder constant definition and enabling effective dead code elimination for feature flags during the build process, leading to optimized bundles.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install nuxt-define"],"cli":null},"imports":["import { addDefinePlugin } from 'nuxt-define'","console.log(__MY_CONSTANT__)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { defineNuxtModule } from '@nuxt/kit';\nimport { addDefinePlugin } from 'nuxt-define';\n\nexport default defineNuxtModule({\n  meta: {\n    name: 'my-feature-module',\n    configKey: 'myFeature'\n  },\n  setup(_options, _nuxt) {\n    // Define compiler constants that will be available globally in your runtime code\n    addDefinePlugin({\n      '__MY_MODULE_VERSION__': JSON.stringify('1.2.3'),\n      '__ENABLE_ANALYTICS__': JSON.stringify(true),\n      '__API_ENDPOINT__': JSON.stringify(process.env.API_ENDPOINT ?? 'https://api.example.com/default')\n    });\n\n    // Example of how these constants might be used in a runtime file (e.g., src/runtime/analytics.ts)\n    // if (__ENABLE_ANALYTICS__) {\n    //   console.log(`Analytics enabled. Module version: ${__MY_MODULE_VERSION__}`);\n    //   // initAnalytics(__API_ENDPOINT__);\n    // }\n\n    console.log('Nuxt module setup completed, constants defined.');\n  }\n});","lang":"typescript","description":"Demonstrates how to import and use `addDefinePlugin` within a Nuxt module's setup function to define global compiler constants.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}