{"id":29791069,"url":"https://github.com/drunomics/nuxt-component-preview","last_synced_at":"2025-07-28T00:13:59.228Z","repository":{"id":299065439,"uuid":"1001723949","full_name":"drunomics/nuxt-component-preview","owner":"drunomics","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-14T22:25:34.000Z","size":158,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"1.x","last_synced_at":"2025-07-17T21:13:53.440Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drunomics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-13T22:26:54.000Z","updated_at":"2025-06-14T22:25:37.000Z","dependencies_parsed_at":"2025-06-14T13:38:36.305Z","dependency_job_id":null,"html_url":"https://github.com/drunomics/nuxt-component-preview","commit_stats":null,"previous_names":["drunomics/nuxt-component-preview"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drunomics/nuxt-component-preview","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fnuxt-component-preview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fnuxt-component-preview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fnuxt-component-preview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fnuxt-component-preview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drunomics","download_url":"https://codeload.github.com/drunomics/nuxt-component-preview/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fnuxt-component-preview/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267442931,"owners_count":24087899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-28T00:13:58.294Z","updated_at":"2025-07-28T00:13:59.215Z","avatar_url":"https://github.com/drunomics.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nuxt Component Preview\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![ci](https://github.com/drunomics/nuxt-component-preview/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/drunomics/nuxt-component-preview/actions/workflows/ci.yml)\n[![License][license-src]][license-href]\n[![Nuxt][nuxt-src]][nuxt-href]\n\n\u003e A Nuxt module by [drunomics](https://drunomics.com/en) for previewing Vue components in external contexts (like iframes or separate HTML pages). Originally developed for use with decoupled Drupal environments, but can be used with any backend.\n\n- [✨ \u0026nbsp;Release Notes](/CHANGELOG.md)\n\n## Features\n\n- 🎭 **Component Preview Mode**: Conditionally render components for previewing in isolation\n- 🚀 **Production Safe**: Inactive by default, only activates when explicitly enabled\n- 🎯 **Target Rendering**: Render components to specific DOM elements using CSS selectors\n- 🧪 **Testing Ready**: Comprehensive test coverage and playground setup\n\n## Quick Setup\n\nInstall the module to your Nuxt application:\n\n```bash\nnpm install nuxt-component-preview\n```\n\nAdd it to your `nuxt.config.ts`:\n\n```ts\nexport default defineNuxtConfig({\n  modules: [\n    'nuxt-component-preview',\n  ],\n  // Optionally configure here\n  // componentPreview: { ... }\n})\n```\n\n## Usage\n\n### Rendering Component Previews\n\nTo render a component preview, use the `\u003cComponentPreviewArea /\u003e` component in your app. \n\n**Example `app.vue`**\n\n```vue\n\u003ctemplate\u003e\n  \u003cComponentPreviewArea v-if=\"useRuntimeConfig().public.componentPreview\" /\u003e\n  \u003cNuxtPage v-else /\u003e\n\u003c/template\u003e\n```\n\n**Important:** Then, when rendering outside of a Nuxt app (e.g., in a static HTML file or external context), you must manually set the runtime config on `window.__NUXT__` before loading the Nuxt entry script to activate it. See the [playground/public/preview-test.html](./playground/public/preview-test.html) for a working example.\n\n#### Example: Setting runtime config in a static HTML file\n\n```html\n\u003cscript\u003e\n  window.__NUXT__ = window.__NUXT__ || {};\n  window.__NUXT__.config = {\n    public: {\n      componentPreview: true\n    }\n  };\n\u003c/script\u003e\n```\n\nYou can then load the Nuxt entry script as shown in [preview-test.html](./playground/public/preview-test.html).\n\nThis setup is ideal for integrating with a Drupal backend (or any backend) that needs to render Nuxt components in isolation, such as for CMS previews or design systems.\n\n**Example: Rendering a component preview via JavaScript**\n\nYou can use the `$previewComponent` method on the Nuxt app instance to dynamically render a component into a target element. For example, in a static HTML file:\n\n```html\n\u003cscript\u003e\n  window.addEventListener('nuxt-component-preview:ready', (event) =\u003e {\n    const { nuxtApp } = event.detail;\n    console.log('Nuxt Component Preview is ready!');\n\n    // Preview TestMarkup component\n    nuxtApp.$previewComponent(\n      'TestMarkup',\n      {\n        content: `\n          \u003cdiv style=\"color: blue;\"\u003e\n            \u003ch2\u003eRendered HTML Content\u003c/h2\u003e\n            \u003cp\u003eThis is \u003cstrong\u003eHTML\u003c/strong\u003e content rendered through the TestMarkup component.\u003c/p\u003e\n          \u003c/div\u003e\n        `\n      },\n      '#preview-target-1'\n    );\n    // ...more examples in preview-test.html\n  });\n\u003c/script\u003e\n```\n\nSee [playground/public/preview-test.html](./playground/public/preview-test.html) for a full working example including multiple components and targets.\n\n## Testing\n\nThis module includes comprehensive tests. To run them:\n\n```bash\nnpm run test\n```\n\n## Releasing\n\nRun command\n```bash\nnpm run release -- --release-as 1.0.0-alpha.1\n```\n\n## About\n\nThis module is maintained by [drunomics](https://drunomics.com/en) and inspired by the needs of decoupled Drupal projects, such as [nuxtjs-drupal-ce](https://github.com/drunomics/nuxtjs-drupal-ce).\n\n---\n\n[npm-version-src]: https://img.shields.io/npm/v/nuxt-component-preview/latest.svg?style=flat-square\n[npm-version-href]: https://npmjs.com/package/nuxt-component-preview\n[npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-component-preview.svg?style=flat-square\n[npm-downloads-href]: https://npmjs.com/package/nuxt-component-preview\n[license-src]: https://img.shields.io/npm/l/nuxt-component-preview.svg?style=flat-square\n[license-href]: https://npmjs.com/package/nuxt-component-preview\n[nuxt-src]: https://img.shields.io/badge/Nuxt-3-green.svg\n[nuxt-href]: https://nuxt.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrunomics%2Fnuxt-component-preview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrunomics%2Fnuxt-component-preview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrunomics%2Fnuxt-component-preview/lists"}