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

@vanilla-dom/babel-plugin

v0.0.0-alpha-20250608081318

Published

Babel plugin for @vanilla-dom JSX compilation

Downloads

4

Readme

@vanilla-dom/babel-plugin

Babel 插件,将 JSX 语法编译为优化的 @vanilla-dom/core VNode 调用,支持编译时优化和组件自动注册。

Installation

pnpm install --save-dev @vanilla-dom/babel-plugin
# 推荐使用 pnpm
pnpm add -D @vanilla-dom/babel-plugin
# 或
yarn add -D @vanilla-dom/babel-plugin

Usage

Basic Setup

Add the plugin to your Babel configuration:

{
  "plugins": ["@vanilla-dom/babel-plugin"]
}

With Options

{
  "plugins": [
    [
      "@vanilla-dom/babel-plugin",
      {
        "importSource": "@vanilla-dom/core",
        "development": false
      }
    ]
  ]
}

Options

  • importSource (string, default: "@vanilla-dom/core"): The module to import hyperscript and Fragment from
  • development (boolean, default: false): Enable development mode features (reserved for future use)

Transformation Examples

Basic Elements

Input:

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

Output:

import { Fragment, hyperscript } from '@vanilla-dom/core';

hyperscript('div', { className: 'container' }, null, 'Hello World');

Custom Components

Input:

<MyComponent prop="value">
  <span>Child</span>
</MyComponent>

Output:

import { Fragment, hyperscript } from '@vanilla-dom/core';

hyperscript(
  MyComponent,
  { prop: 'value' },
  null,
  hyperscript('span', null, null, 'Child'),
);

Fragments

Input:

<>
  <div>First</div>
  <div>Second</div>
</>

Output:

import { Fragment, hyperscript } from '@vanilla-dom/core';

hyperscript(
  Fragment,
  null,
  null,
  hyperscript('div', null, null, 'First'),
  hyperscript('div', null, null, 'Second'),
);

Props and Expressions

Input:

<button onClick={handleClick} disabled={isDisabled}>
  {buttonText}
</button>

Output:

import { Fragment, hyperscript } from '@vanilla-dom/core';

hyperscript(
  'button',
  {
    onClick: handleClick,
    disabled: isDisabled,
  },
  null,
  buttonText,
);

Event Syntax (on: prefix)

Input:

<button on:click={handleClick} className="btn">
  Click me
</button>

Output:

import { Fragment, hyperscript } from '@vanilla-dom/core';

hyperscript('button', { className: 'btn' }, { click: handleClick }, 'Click me');

Spread Attributes

Input:

<div {...props} className="extra">
  Content
</div>

Output:

import { Fragment, hyperscript } from '@vanilla-dom/core';

hyperscript('div', { ...props, className: 'extra' }, null, 'Content');

Integration with Build Tools

Vite

// vite.config.js
import { defineConfig } from 'vite';

export default defineConfig({
  esbuild: {
    jsxFactory: 'hyperscript',
    jsxFragment: 'Fragment',
  },
  plugins: [
    // ... other plugins
  ],
  babel: {
    plugins: ['@vanilla-dom/babel-plugin'],
  },
});

Webpack

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

Rollup

// rollup.config.js
import babel from '@rollup/plugin-babel';

export default {
  plugins: [
    babel({
      plugins: ['@vanilla-dom/babel-plugin'],
      extensions: ['.js', '.jsx', '.ts', '.tsx'],
    }),
  ],
};

TypeScript Support

The plugin works seamlessly with TypeScript. Make sure your tsconfig.json includes:

{
  "compilerOptions": {
    "jsx": "preserve"
  }
}

🚀 编译时优化特性

静态分析优化

  • 静态内容识别:编译时识别静态 HTML 部分
  • 动态插值标记:标记需要运行时更新的位置
  • 事件优化:自动识别可委托的事件处理

组件处理

  • 运行时注册:组件注册交由运行时处理
  • 零配置:无需手动配置组件类型
  • 第三方扩展:支持任何第三方组件编码范式库

转换优化

// 编译前
<div className="container" onClick={handler}>
  <span>{text}</span>
</div>;

// 编译后
hyperscript(
  'div',
  { className: 'container', onClick: handler },
  null,
  hyperscript('span', null, null, text),
);

🔧 高级配置

// babel.config.js
module.exports = {
  plugins: [
    [
      '@vanilla-dom/babel-plugin',
      {
        // 自定义导入源
        importSource: '@vanilla-dom/core',
        // 开发模式调试
        development: process.env.NODE_ENV === 'development',
      },
    ],
  ],
};

🛠️ 开发

# 安装依赖
pnpm install

# 构建插件
pnpm run build

# 运行测试
pnpm run test

# 开发模式
pnpm run dev

License

MIT