import {Meta} from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/scripts/Classes/LibraryPlugin - Vite Plugin Generator'/>

# LibraryPlugin Class

The `LibraryPlugin` class is responsible for generating the Vite plugin entry point for the design system library. This plugin facilitates the automatic integration of components, style variables, and design configurations into the Vite build process.

## Key Features

- **Plugin Entry Generation** — Creates a standard Vite plugin initialization file.
- **Design System Integration** — Connects the components and variables defined in the design configuration to the build tool.
- **Automated Naming** — Automatically generates the plugin name and identifiers based on the design system identifier.
- **Chaining and Flexibility** — Supports method chaining for streamlined library configuration.

## Initialization

To initialize the object, call the `LibraryPlugin(items)` constructor.

**Parameters:**
- `items: LibraryItems` — an object for working with the list of components and managing file writes.

```typescript
import { LibraryPlugin, LibraryItems } from '@dxtmisha/scripts'

// 1. Initialize LibraryItems
const items = new LibraryItems()

// 2. Initialize LibraryPlugin
const pluginGenerator = new LibraryPlugin(items)
```

## Methods

### Control

- `make(): this` — Triggers the generation of the plugin file (`plugin.ts`).

## Generated File Structure

The `make` method generates a `plugin.ts` file that exports a dedicated Vite plugin function. This function facilitates the connection between the compiled library and the build tool.

**Generated Function Profile:**
- **Name:** `ui[Design]VitePlugin` (e.g., `uiDxtVitePlugin`)
- **Parameters:** `options: PluginOptions`
- **Output:** Returns a `VitePlugin` instance.

**Example Structure:**
```typescript
/**
 * Initializes the Vite plugin for the design system.
 * @param options plugin options
 */
export function uiDxtVitePlugin(
  options: PluginOptions = {}
): VitePlugin {
  return new Plugin(
    designName,
    packageName,
    componentsReg,
    styleVarsReg,
    componentsList,
    'vite-plugin-dxt-ui',
    options
  ).init()
}
```


