Piral Vue 2 Plugin

1.10.3 · active · verified Sun Apr 19

Piral-vue is a plugin designed for integrating Vue 2 components within a Piral microfrontend application. It acts as a converter, allowing developers to seamlessly register and render existing or new Vue 2 components as pilets (microfrontends) or parts of pilets. The package is an integral part of the larger Piral ecosystem, which focuses on building scalable and maintainable web portals using a microfrontend architecture, facilitating the combination of different frontend frameworks. As of version 1.10.3, it continues to receive regular updates, typically with minor point releases addressing bug fixes, dependency updates, and improvements within the broader Piral framework, ensuring compatibility and stability within the Piral ecosystem. Its key differentiator is its explicit support for Vue 2, enabling the reuse of established Vue 2 codebases within a modern microfrontend shell. This provides a clear migration path or coexistence strategy for organizations with significant investments in Vue 2 applications, allowing them to incrementally modernize or integrate without forcing an immediate, large-scale upgrade to Vue 3. The plugin handles the necessary lifecycle management and integration points to make Vue 2 components behave as native Piral extensions or pages.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how a Pilet uses `piral-vue` to define and register a Vue 2 component as both a Piral extension and a full page. This quickstart assumes `piral-vue` has been configured in the main Piral instance.

import type { PiletApi } from 'piral';
import { defineComponent } from 'vue'; // Ensure vue@2 is a dependency in your pilet

// Extend PiletApi with piral-vue specific functions provided by the Piral instance.
// This assumes 'piral-vue' has been configured in the Piral instance's createInstance call.
interface MyPiletApi extends PiletApi {
  fromVue(component: any): any; // The actual type is VueComponentConverter<VueComponent>
}

// Define a simple Vue 2 component
const MyVueComponent = defineComponent({
  name: 'MyVueComponent',
  props: {
    message: {
      type: String,
      default: 'Hello from Vue 2 Pilet!',
    },
  },
  template: `
    <div style="padding: 10px; border: 1px solid #42b983; margin: 10px; border-radius: 5px;">
      <h3>{{ message }}</h3>
      <p>This is a Vue 2 component served by a Pilet.</p>
      <button @click="increment">Count: {{ count }}</button>
    </div>
  `,
  data() {
    return {
      count: 0,
    };
  },
  methods: {
    increment() {
      this.count++;
    },
  },
});

/**
 * The setup function for the Pilet.
 * It registers a Vue component as an extension and a page within the Piral application.
 */
export function setup(app: MyPiletApi) {
  // Register the Vue component as an extension.
  // It can be embedded anywhere in the Piral app using <Extension name="vue-pilet-card" />.
  app.registerExtension('vue-pilet-card', app.fromVue(MyVueComponent));

  // Register the Vue component as a full page, accessible via a route.
  app.registerPage('/vue-pilet-page', app.fromVue(MyVueComponent));

  console.log('Vue 2 Pilet: MyVueComponent registered as extension "vue-pilet-card" and page "/vue-pilet-page".');
}

view raw JSON →