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

@thinke/babel-plugin-solidjs-on-react

v0.1.6

Published

让 SolidJS 和 React 共存

Readme

@thinke/babel-plugin-solidjs-on-react

自动为 SolidJS 组件添加 withSolid 工厂函数包装的 Babel 插件。

🚀 功能特性

  • 🔧 自动转换:自动检测并转换包含 JSX 的组件函数
  • 🎯 智能识别:支持多种组件定义方式的自动识别
  • 零配置:开箱即用,无需额外配置
  • 🛠️ 可定制:支持自定义 withSolid 函数名和导入路径
  • 🔍 防重复:智能检测已包装的组件,避免重复转换
  • 📦 自动导入:自动添加 withSolid 导入语句

📦 安装

npm install --save-dev @thinke/babel-plugin-solidjs-on-react
# 或
yarn add --dev @thinke/babel-plugin-solidjs-on-react
# 或
pnpm add --dev @thinke/babel-plugin-solidjs-on-react

🛠️ 配置

基础配置

在你的 Babel 配置文件(.babelrcbabel.config.js)中添加插件:

module.exports = {
  presets: ['@babel/preset-env'],
  plugins: ['@thinke/babel-plugin-solidjs-on-react']
}

高级配置

module.exports = {
  presets: ['@babel/preset-env'],
  plugins: [
    [
      '@thinke/babel-plugin-solidjs-on-react',
      {
        // 自定义 withSolid 函数名
        withSolidFunctionName: 'MyWithSolid',
        // 自定义导入路径
        withSolidImportPath: '@my-custom-path/MyWithSolid'
      }
    ]
  ]
}

配置选项

| 选项 | 类型 | 默认值 | 描述 | | ----------------------- | -------- | -------------------------------------- | ---------------------- | | withSolidFunctionName | string | "withSolid" | 指定包装函数的名称 | | withSolidImportPath | string | "@thinke/solidjs-on-react/withSolid" | 指定包装函数的导入路径 |

支持 函数体内的指令

包装

export const Component2 = () => {
  'with solid'

  return (
    <div>
      <h1 class="hello">hello world</h1>
    </div>
  )
}

不包装

export const Component2 = () => {
  'not with solid'

  return (
    <div>
      <h1 class="hello">hello world</h1>
    </div>
  )
}

🎯 支持的组件类型

插件支持以下组件定义形式的自动转换:

1. 箭头函数组件

// 转换前
export const Component1 = () => {
  return (
    <div>
      <h1 class="hello">hello world</h1>
    </div>
  );
};

// 转换后
import { withSolid } from "@thinke/solidjs-on-react/withSolid";
export const Component1 = withSolid(() => {
  return (
    <div>
      <h1 class="hello">hello world</h1>
    </div>
  );
});

2. 函数声明组件

// 转换前
export function Component2() {
  return (
    <div>
      <h1 class="hello">hello world</h1>
    </div>
  );
}

// 转换后
import { withSolid } from "@thinke/solidjs-on-react/withSolid";
export const Component2 = withSolid(() => {
  return (
    <div>
      <h1 class="hello">hello world</h1>
    </div>
  );
});

🔍 转换规则

自动检测条件

插件会自动检测满足以下条件的组件:

  1. 返回 JSX:函数体或箭头函数直接返回 JSX 元素或 JSX 片段
  2. 函数类型:支持以下函数类型:
    • 箭头函数表达式 (() => {})
    • 函数声明 (function Component() {})

智能忽略

插件会智能跳过以下情况:

  • 已经被 withSolid 包装的组件
  • 不返回 JSX 的函数
  • 非函数类型的节点

自动导入

当检测到需要包装的组件时,插件会:

  1. 检查文件是否已导入 withSolid 函数
  2. 如果未导入,自动在文件顶部添加导入语句
  3. 导入语句会插入到其他导入语句之后,代码之前

⚠️ 注意事项

  1. 组件必须有返回值:组件必须返回 JSX 才会被转换
  2. 函数声明转换:函数声明会被转换为变量声明
  3. 导入冲突:请确保 withSolid 函数名不与现有导入冲突
  4. TypeScript 支持:插件完全支持 TypeScript 文件

🤝 贡献

欢迎提交 Issue 和 Pull Request 来改进这个插件!

📄 许可证

MIT License

🔗 相关链接