npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vira-ui/babel-plugin

v3.1.0

Published

Babel plugin for ViraJS JSX transformation

Readme

@vira-ui/babel-plugin

Babel плагин для трансформации JSX в вызовы createElement от Vira Framework.

📦 Установка

npm install --save-dev @vira-ui/babel-plugin @babel/core

Требования:

  • @babel/core ^7.0.0

🎯 Что это?

Плагин трансформирует JSX синтаксис в вызовы createElement из @vira-ui/core, что позволяет использовать декларативный синтаксис JSX с Vira Framework.

🚀 Использование

Babel конфигурация

.babelrc / babel.config.js

{
  "plugins": [
    ["@vira-ui/babel-plugin", {
      "pragma": "createElement",
      "pragmaFrag": "Fragment"
    }]
  ]
}

Vite

// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: [
          ['@vira-ui/babel-plugin', {
            pragma: 'createElement',
            pragmaFrag: 'Fragment'
          }]
        ]
      }
    })
  ]
});

Webpack

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx|ts|tsx)$/,
        use: {
          loader: 'babel-loader',
          options: {
            plugins: [
              ['@vira-ui/babel-plugin', {
                pragma: 'createElement',
                pragmaFrag: 'Fragment'
              }]
            ]
          }
        }
      }
    ]
  }
};

⚙️ Опции

pragma

Имя функции для создания элементов. По умолчанию: "createElement".

{
  "plugins": [
    ["@vira-ui/babel-plugin", {
      "pragma": "h"  // Использовать h() вместо createElement()
    }]
  ]
}

pragmaFrag

Имя функции для Fragment. По умолчанию: "Fragment".

{
  "plugins": [
    ["@vira-ui/babel-plugin", {
      "pragmaFrag": "Fragment"  // Использовать Fragment() для <>
    }]
  ]
}

useBuiltIns

Использовать встроенные функции вместо импорта. По умолчанию: false.

development

Режим разработки (добавляет дополнительную информацию). По умолчанию: false.

📝 Примеры трансформации

Простой элемент

До:

<div className="container">
  <h1>Hello</h1>
</div>

После:

createElement('div', { className: 'container' },
  createElement('h1', {}, 'Hello')
)

Компонент

До:

<Button onClick={handleClick} disabled={isDisabled}>
  Click me
</Button>

После:

createElement(Button, {
  onClick: handleClick,
  disabled: isDisabled
}, 'Click me')

Fragment

До:

<>
  <div>Item 1</div>
  <div>Item 2</div>
</>

После:

Fragment({},
  createElement('div', {}, 'Item 1'),
  createElement('div', {}, 'Item 2')
)

Выражения

До:

<div>
  {count > 0 && <span>{count}</span>}
  {items.map(item => <Item key={item.id} {...item} />)}
</div>

После:

createElement('div', {},
  count > 0 && createElement('span', {}, count),
  items.map(item => createElement(Item, { key: item.id, ...item }))
)

🔧 Автоматический импорт

Плагин автоматически добавляет импорт createElement из @vira-ui/core, если его нет:

// Автоматически добавляется
import { createElement } from '@vira-ui/core';

🎨 Интеграция с Vira Framework

Использование с defineComponent

import { defineComponent } from '@vira-ui/core';

const MyComponent = defineComponent({
  props: { name: String },
  render: ({ name }) => (
    <div>
      <h1>Hello {name}</h1>
    </div>
  )
});

Трансформируется в:

const MyComponent = defineComponent({
  props: { name: String },
  render: ({ name }) => createElement('div', {},
    createElement('h1', {}, 'Hello ', name)
  )
});

Использование с компонентами UI

import { Button, Input } from '@vira-ui/ui';

function MyForm() {
  return (
    <form>
      <Input placeholder="Name" />
      <Button preset="primary">Submit</Button>
    </form>
  );
}

🚀 Оптимизации

Плагин выполняет следующие оптимизации:

  1. Статические элементы — простые элементы остаются простыми
  2. Удаление пустых текстовых узлов — пробелы и переносы строк удаляются
  3. Оптимизация props — пустые объекты не создаются

🔍 Отладка

Для отладки трансформации используйте Babel REPL:

  1. Откройте Babel REPL
  2. Добавьте плагин @vira-ui/babel-plugin
  3. Введите ваш JSX код
  4. Посмотрите результат трансформации

📖 Примеры конфигурации

TypeScript + Vite

// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: [
          ['@vira-ui/babel-plugin', {
            pragma: 'createElement',
            pragmaFrag: 'Fragment'
          }]
        ]
      }
    })
  ]
});

Next.js

// next.config.js
module.exports = {
  webpack: (config) => {
    config.module.rules.push({
      test: /\.(js|jsx|ts|tsx)$/,
      use: {
        loader: 'babel-loader',
        options: {
          plugins: [
            ['@vira-ui/babel-plugin', {
              pragma: 'createElement',
              pragmaFrag: 'Fragment'
            }]
          ]
        }
      }
    });
    return config;
  }
};

🐛 Troubleshooting

Импорт не добавляется

Если импорт createElement не добавляется автоматически:

  1. Убедитесь, что плагин правильно настроен
  2. Проверьте порядок плагинов (должен быть последним)
  3. Добавьте импорт вручную:
import { createElement } from '@vira-ui/core';

Конфликты с другими плагинами

Если есть конфликты с другими Babel плагинами:

  1. Измените порядок плагинов
  2. Используйте @babel/plugin-transform-react-jsx вместо стандартного React плагина
  3. Настройте опции для избежания конфликтов

📄 License

MIT

🔗 Связанные пакеты