# @fattafatta/babel-preset-rescript-solidjs

> Babel preset to transform ReScript code to solidJs.

Latest version **0.2.2** (published 2023-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fattafatta/babel-preset-rescript-solidjs
pnpm add @fattafatta/babel-preset-rescript-solidjs
yarn add @fattafatta/babel-preset-rescript-solidjs
bun add @fattafatta/babel-preset-rescript-solidjs
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2023-03-13 |
| First published | 2022-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 23.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Fattafatta |
| Maintainers | fattafatta |
| Keywords | rescript, solid, solidjs, babel, preset |

## Links

- npm: https://www.npmjs.com/package/@fattafatta/babel-preset-rescript-solidjs
- npm.io page: https://npm.io/package/@fattafatta/babel-preset-rescript-solidjs

## Dependencies (2)

- [babel-preset-solid](https://npm.io/package/babel-preset-solid.md) ^1.4.4
- [@fattafatta/babel-plugin-rescript-react-to-jsx](https://npm.io/package/@fattafatta/babel-plugin-rescript-react-to-jsx.md) ^0.3.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2023-03-13
- 0.2.1 — 2023-03-12
- 0.2.0 — 2023-03-10
- 0.1.3 — 2022-07-02
- 0.1.2 — 2022-06-21
- 0.1.1 — 2022-06-20
- 0.1.0 — 2022-06-20

## README

# babel-preset-rescript-solidjs

Applies all necessary transformations to compile [ReScript](https://rescript-lang.org/) code to [solidJs](https://github.com/solidjs/solid).

The original code compiled by `ReScript` is not compatible with `solid`. First, the ReScript compiler breaks reactivity by reassigning component properties to variables. And second, `solid` compiler expects JSX, but ReScript compiles all JSX directly to JavaScript.

This preset replaces the variable assignments and transforms the `ReScript` JavaScript code back to JSX. Afterwards it runs the [preset](https://github.com/solidjs/solid/tree/main/packages/babel-preset-solid) provided by `solid` to compile the code.

## Installation

```sh
$ npm install @fattafatta/babel-preset-rescript-solidjs --save-dev

# or

yarn add @fattafatta/babel-preset-rescript-solidjs --dev
```

## Usage

The plugin supports JSX versions 3 and 4 with automatic version detection.

### Via config file

Add this to your `.babelrc`:

```json
{
  "presets": ["@fattafatta/babel-preset-rescript-solidjs"]
}
```

### With `vite`

Install `vite-plugin-babel` and `@jihchi/vite-plugin-rescript`:

```shell
npm install vite-plugin-babel @jihchi/vite-plugin-rescript --save-dev

# or
yarn add vite-plugin-babel @jihchi/vite-plugin-rescript --dev
```

Configure `vite.config.js`

```js
import { defineConfig } from "vite";
import createReScriptPlugin from "@jihchi/vite-plugin-rescript";
import babel from "vite-plugin-babel";

export default defineConfig({
  plugins: [
    createReScriptPlugin(),
    babel({
      babelConfig: {
        presets: ["@fattafatta/babel-preset-rescript-solidjs"],
      },
    }),
  ],
  resolve: {
    dedupe: ['solid-js'],
  },
});
```

**Note**: Sometimes `vite` bundles parts of the `solidJS` dependencies twice, which results in errors (like lazy components not loading correctly). If you get the warning `You appear to have multiple instances of Solid. This can lead to unexpected behavior.`, use the option `resolve.dedupe` like above and the problem should be fixed.

The babel plugin works with either the `.babelrc` file or by passing the config directly.

### Via CLI

Make sure to use the correct file extension when transforming files. ReScript files end on `.bs.js`. But JSX files should use `.jsx`.

```sh
babel --no-babelrc --presets @fattafatta/babel-preset-rescript-solidjs script.bs.js > script.jsx
```

---
_Source: https://npm.io/package/@fattafatta/babel-preset-rescript-solidjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
