{"_id":"@crazydos/nuxt-configs","_rev":"3-9f8804048e565f3f242600ab1c64deed","name":"@crazydos/nuxt-configs","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@crazydos/nuxt-configs","version":"0.1.0","author":{"url":"https://github.com/shunnNet","name":"shunnNet","email":"wendell20904102@gmail.com"},"license":"MIT","_id":"@crazydos/nuxt-configs@0.1.0","maintainers":[{"name":"crazydos","email":"wendell20904102@gmail.com"}],"homepage":"https://github.com/shunnNet/nuxt-configs#readme","bugs":{"url":"https://github.com/shunnNet/nuxt-configs/issues"},"dist":{"shasum":"98b97e66997cbc91f894a9658c81343e1ca138d3","tarball":"https://registry.npmjs.org/@crazydos/nuxt-configs/-/nuxt-configs-0.1.0.tgz","fileCount":21,"integrity":"sha512-IDeKcbvUTL1O6gX1a4I0065r8yplkD3iEB7QEbWmbUc3zKkJUDSqXnPWMoCD31V8yRYyuhvXFA9TNGfuqJ5lyA==","signatures":[{"sig":"MEQCIDCs9zyhVGPcbIOX7cpeeF4u8swbFjVQBQYEvdI0JZRmAiAkOMWkromRaHJJlGPi2h0iTn/1kTy/Vi4WTg9zednMSA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16575},"main":"./dist/module.cjs","type":"module","_from":"file:crazydos-nuxt-configs-0.1.0.tgz","types":"./dist/types.d.ts","exports":{".":{"types":"./dist/types.d.ts","import":"./dist/module.mjs","require":"./dist/module.cjs"},"./utils":{"types":"./dist/runtime/utils.d.ts","import":"./dist/runtime/utils.js"}},"scripts":{"dev":"nuxi dev playground","lint":"eslint .","test":"vitest run","release":"npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags","dev:build":"nuxi build playground","test:types":"vue-tsc --noEmit && cd playground && vue-tsc --noEmit","test:watch":"vitest watch","dev:prepare":"nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground"},"_npmUser":{"name":"crazydos","email":"wendell20904102@gmail.com"},"_resolved":"/private/var/folders/cy/dkhc_bx936146krjt5tptv4m0000gn/T/af95c34c28901767a4c35ed108e545fd/crazydos-nuxt-configs-0.1.0.tgz","_integrity":"sha512-IDeKcbvUTL1O6gX1a4I0065r8yplkD3iEB7QEbWmbUc3zKkJUDSqXnPWMoCD31V8yRYyuhvXFA9TNGfuqJ5lyA==","repository":{"url":"git+https://github.com/shunnNet/nuxt-configs.git","type":"github"},"_npmVersion":"10.5.0","description":"Shareable configs for nuxt and nitro runtimes.","directories":{},"_nodeVersion":"20.12.2","dependencies":{"defu":"^6.1.4","pathe":"^2.0.3","@nuxt/kit":"^3.16.0","fast-glob":"^3.3.3"},"_hasShrinkwrap":false,"devDependencies":{"nuxt":"^3.16.0","eslint":"^9.22.0","vitest":"^3.0.8","vue-tsc":"^2.2.8","typescript":"~5.8.2","@types/node":"latest","changelogen":"^0.6.1","@nuxt/eslint":"1.2.0","@nuxt/schema":"^3.16.0","@nuxt/devtools":"^2.3.0","@nuxt/test-utils":"^3.17.2","@nuxt/eslint-config":"^1.2.0","@nuxt/module-builder":"^0.8.4"},"_npmOperationalInternal":{"tmp":"tmp/nuxt-configs_0.1.0_1742135080227_0.6217278654741201","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@crazydos/nuxt-configs","version":"0.1.1","author":{"url":"https://github.com/shunnNet","name":"shunnNet","email":"wendell20904102@gmail.com"},"license":"MIT","_id":"@crazydos/nuxt-configs@0.1.1","maintainers":[{"name":"crazydos","email":"wendell20904102@gmail.com"}],"homepage":"https://github.com/shunnNet/nuxt-configs#readme","bugs":{"url":"https://github.com/shunnNet/nuxt-configs/issues"},"dist":{"shasum":"d18003782d2eb743cc53d46224226db94e67cefd","tarball":"https://registry.npmjs.org/@crazydos/nuxt-configs/-/nuxt-configs-0.1.1.tgz","fileCount":21,"integrity":"sha512-ZbRj6il1wNv+AfF4y3hH9QJDqfpTsrPwNQt6Ungxbik2BgNTTLM04FtQQ+cl9TplJuG+48GC+Xi8/Yatrgf0gw==","signatures":[{"sig":"MEYCIQDHiOrQyFeenzdRrc/jLJR7WUXtE7cwtYdEOO6+1FGEcgIhANNwDbJokOJQ5GQqpWMorkXxoLWEwT9cOCF6cEt2+FQ5","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16567},"main":"./dist/module.cjs","type":"module","_from":"file:crazydos-nuxt-configs-0.1.1.tgz","types":"./dist/types.d.ts","exports":{".":{"types":"./dist/types.d.ts","import":"./dist/module.mjs","require":"./dist/module.cjs"},"./utils":{"types":"./dist/runtime/utils.d.ts","import":"./dist/runtime/utils.js"}},"scripts":{"dev":"nuxi dev playground","lint":"eslint .","test":"vitest run","release":"npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags","dev:build":"nuxi build playground","test:types":"vue-tsc --noEmit && cd playground && vue-tsc --noEmit","test:watch":"vitest watch","dev:prepare":"nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground"},"_npmUser":{"name":"crazydos","email":"wendell20904102@gmail.com"},"_resolved":"/private/var/folders/cy/dkhc_bx936146krjt5tptv4m0000gn/T/c0a14984e1b13d1208b10d2ea23a3137/crazydos-nuxt-configs-0.1.1.tgz","_integrity":"sha512-ZbRj6il1wNv+AfF4y3hH9QJDqfpTsrPwNQt6Ungxbik2BgNTTLM04FtQQ+cl9TplJuG+48GC+Xi8/Yatrgf0gw==","repository":{"url":"git+https://github.com/shunnNet/nuxt-configs.git","type":"github"},"_npmVersion":"10.5.0","description":"Shareable configs for nuxt and nitro runtimes.","directories":{},"_nodeVersion":"20.12.2","dependencies":{"defu":"^6.1.4","pathe":"^2.0.3","@nuxt/kit":"^3.16.0","fast-glob":"^3.3.3"},"_hasShrinkwrap":false,"devDependencies":{"nuxt":"^3.16.0","eslint":"^9.22.0","vitest":"^3.0.8","vue-tsc":"^2.2.8","typescript":"~5.8.2","@types/node":"latest","changelogen":"^0.6.1","@nuxt/eslint":"1.2.0","@nuxt/schema":"^3.16.0","@nuxt/devtools":"^2.3.0","@nuxt/test-utils":"^3.17.2","@nuxt/eslint-config":"^1.2.0","@nuxt/module-builder":"^0.8.4"},"_npmOperationalInternal":{"tmp":"tmp/nuxt-configs_0.1.1_1742136209537_0.5838888919720715","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@crazydos/nuxt-configs","version":"0.1.2","description":"Shareable configs for nuxt and nitro runtimes.","author":{"name":"shunnNet","email":"wendell20904102@gmail.com","url":"https://github.com/shunnNet"},"repository":{"type":"github","url":"git+https://github.com/shunnNet/nuxt-configs.git"},"license":"MIT","type":"module","exports":{".":{"types":"./dist/types.d.ts","import":"./dist/module.mjs","require":"./dist/module.cjs"},"./utils":{"types":"./dist/runtime/utils.d.ts","import":"./dist/runtime/utils.js"}},"main":"./dist/module.cjs","types":"./dist/types.d.ts","dependencies":{"@nuxt/kit":"^3.16.0","defu":"^6.1.4","fast-glob":"^3.3.3","pathe":"^2.0.3"},"devDependencies":{"@nuxt/devtools":"^2.3.0","@nuxt/eslint":"1.2.0","@nuxt/eslint-config":"^1.2.0","@nuxt/module-builder":"^0.8.4","@nuxt/schema":"^3.16.0","@nuxt/test-utils":"^3.17.2","@types/node":"latest","changelogen":"^0.6.1","eslint":"^9.22.0","nuxt":"^3.16.0","typescript":"~5.8.2","vitest":"^3.0.8","vue-tsc":"^2.2.8"},"scripts":{"dev":"nuxi dev playground","dev:build":"nuxi build playground","dev:prepare":"nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground","release":"npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags","lint":"eslint .","test":"vitest run","test:watch":"vitest watch","test:types":"vue-tsc --noEmit && cd playground && vue-tsc --noEmit"},"bugs":{"url":"https://github.com/shunnNet/nuxt-configs/issues"},"homepage":"https://github.com/shunnNet/nuxt-configs#readme","_id":"@crazydos/nuxt-configs@0.1.2","_integrity":"sha512-A6ULWEXWtO1ZAd78/n8/zz8ldh88f7IdTQPC/phUlVRnjIJ3wD4C5/6fHkhhD3RPPTR+QFQ6OQAAhcAjKLvV9A==","_resolved":"/private/var/folders/cy/dkhc_bx936146krjt5tptv4m0000gn/T/b1004e38ce42ad50cf360af307aacc8d/crazydos-nuxt-configs-0.1.2.tgz","_from":"file:crazydos-nuxt-configs-0.1.2.tgz","_nodeVersion":"20.12.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-A6ULWEXWtO1ZAd78/n8/zz8ldh88f7IdTQPC/phUlVRnjIJ3wD4C5/6fHkhhD3RPPTR+QFQ6OQAAhcAjKLvV9A==","shasum":"9ea3703a20fe8a56ca41508753696dc99093bfe5","tarball":"https://registry.npmjs.org/@crazydos/nuxt-configs/-/nuxt-configs-0.1.2.tgz","fileCount":21,"unpackedSize":16597,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIE53VVf+J7QP/zM8TB6s3mCqQ8f/QyxhYOZu5ehfYpR5AiAtkzAtDJ9e0ZYK6LlEWK3AeRNv5VBEcea6T41yxicWGQ=="}]},"_npmUser":{"name":"crazydos","email":"wendell20904102@gmail.com"},"directories":{},"maintainers":[{"name":"crazydos","email":"wendell20904102@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nuxt-configs_0.1.2_1742136742631_0.7157030464421827"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-16T14:24:40.118Z","modified":"2025-03-16T14:52:22.992Z","0.1.0":"2025-03-16T14:24:40.431Z","0.1.1":"2025-03-16T14:43:29.738Z","0.1.2":"2025-03-16T14:52:22.841Z"},"bugs":{"url":"https://github.com/shunnNet/nuxt-configs/issues"},"author":{"name":"shunnNet","email":"wendell20904102@gmail.com","url":"https://github.com/shunnNet"},"license":"MIT","homepage":"https://github.com/shunnNet/nuxt-configs#readme","repository":{"type":"github","url":"git+https://github.com/shunnNet/nuxt-configs.git"},"description":"Shareable configs for nuxt and nitro runtimes.","maintainers":[{"name":"crazydos","email":"wendell20904102@gmail.com"}],"readme":"<!--\nGet your module up and running quickly.\n\nFind and replace all on all files (CMD+SHIFT+F):\n- Name: My Module\n- Package name: my-module\n- Description: My new Nuxt module\n-->\n\n# nuxt-configs\n\n[![npm version](https://img.shields.io/npm/v/@crazydos/nuxt-configs.svg?style=flat&colorA=18181B&colorB=28CF8D)](https://www.npmjs.com/package/@crazydos/nuxt-configs)\n[![npm downloads](https://img.shields.io/npm/dm/@crazydos/nuxt-configs.svg?style=flat&colorA=18181B&colorB=28CF8D)](https://www.npmjs.com/package/@crazydos/nuxt-configs)\n[![License](https://img.shields.io/github/license/nuxt/nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D)](https://github.com/shunnNet/nuxt-configs/blob/main/LICENSE)\n[![Nuxt Logo](https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js)](https://nuxt.com/)\n\nAutomatically load configs for nuxt and nitro runtimes from the `~/configs` directory. This may be useful for nuxt module configs requiring non-serialzable values. If you are not a module author, you can still use this module to provide common configurations for your Nuxt and Nitro.\n\n<!-- - [✨ &nbsp;Release Notes](/CHANGELOG.md) -->\n<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->\n<!-- - [📖 &nbsp;Documentation](https://example.com) -->\n\n## Features\n\n<!-- Highlight some of the features your module provide here -->\n- 🌲 Provide a common configuration interface (`~/configs`) that allows various Nuxt modules to access and be used in both Nuxt and Nitro runtimes.\n\n- [nuxt-configs](#nuxt-configs)\n  - [Features](#features)\n  - [Usage (common)](#usage-common)\n    - [`app.ts`](#appts)\n    - [`nitro.ts`](#nitrots)\n  - [Usage (Nuxt module)](#usage-nuxt-module)\n  - [Layer](#layer)\n  - [Why?](#why)\n  - [License](#license)\n\n\n\n## Usage (common)\nInstall the module to your Nuxt application.\n\n```sh\nnpm install -D @crazydos/nuxt-configs\n```\n\n```ts\nexport default defineNuxtConfig({\n  modules: ['@crazydos/nuxt-configs'],\n})\n```\n\nAfter setting it up, you can configure `app.ts` (for the Nuxt environment) and `nitro.ts` (for the Nitro environment) in the `<rootDir>/configs` directory.\n\n```\n|--<rootDir>\n|--/configs <-- (here)\n|----app.ts <---- (for the Nuxt environment)\n|----nitro.ts <-- (for the Nuxt environment)\n|--app.vue\n|--/pages\n```\n\n\n### `app.ts`\nThe configuration in `app.ts` can be accessed within the Nuxt runtime, including `.vue` files, `plugins`, and other related files. The configuration is set up as follows:\n\n```ts\n// configs/app.ts\nimport { defineNuxtAppConfig } from '#configs'\n\nexport default defineNuxtAppConfig({\n  foo: {\n    name: \"foo\",\n    bar: () => {}\n  }\n})\n```\n\n```vue\n<!-- app.vue -->\n<script setup lang=\"ts\">\nconst configs = useNuxtAppConfig()\n\nconfigs.foo.name\nconfigs.foo.bar()\n</script>\n```\n\nYou can define the type for the config using the following approach. First, create a `.d.ts` file in the rootDir, then:\n\n```ts\n// <rootDir>/global.d.ts\ndeclare module '#build/client.config.mjs' {\n  export const configs: {\n    // e.g: \n    foo: {\n      name: string,\n      bar: CallableFunction\n    }\n  }\n}\n```\n\n> [!WARNING]\n> Configuration in `app.ts` may be exposed in browser, **DON't put any secret, credentials in it.**\n\n### `nitro.ts`\nThe configuration in `nitro.ts` can be accessed within the `Nitro` runtime, including files under `server/api` and `server/plugins`, etc. The configuration is set up as follows:\n\n```ts\n// configs/nitro.ts\nimport { defineNuxtNitroConfig } from '#configs'\n\nexport default defineNuxtNitroConfig({\n  foo: {\n    name: \"foo\",\n    bar: () => {}\n  }\n})\n```\n\n```ts\nexport default defineNitroPlugin(() => {\n  const config = useNuxtNitroConfig()\n  config.foo.bar()\n})\n```\n\nYou can define the type for the config using the following approach. First, create a `.d.ts` file in the rootDir, then:\n\n```ts\n// <rootDir>/global.d.ts\ndeclare module '#configs/nitro' {\n  export const configs: {\n    // e.g: \n    foo: {\n      name: string,\n      bar: CallableFunction\n    }\n  }\n}\n```\n\n## Usage (Nuxt module)\nIf you are using this module in your own Nuxt project, you can refer to the [`Usage (common)`](#usage-common) section above.\nIf you are a module package author, you can use the interface provided by this module as follows:\n\nFirst, you need to add `@crazydos/nuxt-configs` as a dependency and install this module within your own Nuxt module.\n\n```sh\nnpm install @crazydos/nuxt-configs\n```\n\n```ts\nimport { installModule } from '@nuxt/kit'\nexport default defineNuxtModule<ModuleOptions>({\n  // ...\n  setup(_options, _nuxt) {\n    installModule('@crazydos/nuxt-configs')\n  }\n})\n```\n\nNext, you can define the type for your module’s configuration by `.d.ts`.\n\n```ts\n// src/runtime/config.nitro.d.ts\ndeclare module '#configs/nitro' {\n  /** define myModule nitro options */\n  const myModule: Record<string, unknown>\n}\n```\n\n```ts\n// src/runtime/config.nuxt.d.ts\ndeclare module '#build/client.config.mjs' {\n  /** define myModule client options */\n  const myModule: Record<string, unknown>\n}\n```\n\n> [!NOTE]\n> Put these `.d.ts` in runtime directory.\n\nLast, add these type files by helpers export from `@crazydos/nuxt-configs/utils`.\n\n```ts\nimport { installModule } from '@nuxt/kit'\nexport default defineNuxtModule<ModuleOptions>({\n  // ...\n  setup(_options, _nuxt) {\n    installModule('@crazydos/nuxt-configs')\n\n    // Add .d.ts to buildDir or it will lost.\n    const resolver = createResolver(import.meta.url)\n    addAppConfigTypeFile(_nuxt, 'myModule', resolver.resolve('./runtime/config.nuxt.d.ts'))\n    addNitroConfigTypeFile(_nuxt, 'myModule', resolver.resolve('./runtime/config.nitro.d.ts'))\n  }\n})\n```\n\nFinally, you can instruct your users to place your module’s configuration in `<rootDir>/configs/app.ts` and `<rootDir>/configs/nitro.ts`. You can then use these configurations within your module's runtime code.\n\n\n```ts\n// src/runtime/server/plugins.ts\nexport default defineNitroPlugin(() => {\n  const configs = useNuxtNitroConfig()\n  console.log('nitro config:', configs.myModule)\n})\n```\n\n## Layer\n> [!WARNING]\n> Currently, layers are not supported.\n\n--- \n\n## Why?\nWhen developing a Nuxt module, user configurations can be received through nuxt.config.ts. However, since nuxt.config.ts exists in the build environment and is separate from the Nitro and Nuxt runtimes, these configurations cannot be used directly at runtime. Instead, they need to be passed to the runtime through certain mechanisms, such as `runtimeConfig` or methods like `addTemplate`.\n\nThe simplest approach is `runtimeConfig`, but it can only pass serializable configurations and cannot handle functions or other non-serializable values.\n```ts\n// nuxt.config.ts\nexport default defineNuxtConfig({\n  modules: ['some-module'],\n  someModule: {\n    foo: \"bar\",\n    func: () => {} // this cannot easily pass to runtime environment\n  }\n})\n```\n\n```ts\nexport default defineNuxtModule<ModuleOptions>({\n  // ...\n  setup(_options, _nuxt) {\n    _nuxt.options.runtimeConfig.myModule.foo = _options.foo\n  }\n})\n```\n\nOn the other hand, the `addTemplate` method is not very straightforward and has a certain learning curve.\n\nThis module provides a simple way for module developers to easily receive configurations and seamlessly apply them in both `Nitro` and `Nuxt` runtimes, avoiding the issues mentioned above.\n\n```ts\n// configs/nitro.ts\nimport { defineNuxtNitroConfig } from '#configs'\n\nexport default defineNuxtNitroConfig({\n  foo: {\n    name: \"foo\",\n    bar: () => {}\n  }\n})\n```\n\nIn reality, it seems that only the `Nitro` environment lacks such an interface (?), since Nuxt already provides `app.config.ts`. A better solution might be for Nuxt to introduce `nitro.config.ts`, which would eliminate the need for this module altogether.\n\n## License\n[MIT](./LICENSE)\n\n\n","readmeFilename":"README.md"}