Skip to content

Commit 61630ad

Browse files
committed
feat: set up bun plugin
1 parent 5e8cf6e commit 61630ad

26 files changed

+992
-658
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.github/workflows/ci.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ jobs:
1818
- name: Setup Bun
1919
uses: oven-sh/setup-bun@v1
2020
with:
21-
bun-version: 1.2.3
21+
bun-version: 1.2.12
2222
- name: Install Dependencies
2323
run: bun install --frozen-lockfile
24+
- name: Type Check
25+
run: bun run typecheck
2426
- name: Lint Check
2527
run: bun run lint
2628
- name: Format Check
2729
run: bun run format
30+
- name: Run Tests
31+
run: bun test:cov

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Daniel Sanchez
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 110 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,132 @@
11
<p>
2-
<img width="100%" src="https://assets.solidjs.com/banner?type=Ecosystem&background=tiles&project=library-name" alt="solid-create-script">
2+
<img width="100%" src="https://assets.solidjs.com/banner?type=Ecosystem&background=tiles&project=bun-plugin-solid" alt="bun-plugin-solid">
33
</p>
44

5-
# Template: SolidJS Library
5+
# @dschz/bun-plugin-solid
66

7-
Template for [SolidJS](https://www.solidjs.com/) library package. Bundling of the library is managed by [tsup](https://tsup.egoist.dev/).
7+
MIT Licensed
88

9-
Other things configured include:
9+
> 🧩 A Bun plugin for transforming SolidJS JSX/TSX files at runtime or build time using Babel. Supports SSR and DOM output.
1010
11-
- Bun (for dependency management and running scripts)
12-
- TypeScript
13-
- ESLint / Prettier
14-
- Solid Testing Library + Vitest (for testing)
15-
- Playground app using library
16-
- GitHub Actions (for all CI/CD)
11+
> ⚠️ **Note**: This plugin is designed specifically for use with the [Bun runtime](https://bun.sh). It will not work in Node.js, Deno, or other JavaScript environments.
1712
18-
## Getting Started
13+
## Features
1914

20-
Some pre-requisites before install dependencies:
15+
- ✅ Works in both `bun run` (runtime) and `bun build` (build-time) contexts
16+
- 🎯 Supports SSR (`generate: "ssr"`) and DOM (`generate: "dom"`) output
17+
- 💧 Hydratable output toggle for SSR
18+
- 🧱 Designed to be invoked via `preload` or build plugins
19+
- 🪄 Minimal and explicit configuration surface
2120

22-
- Install Node Version Manager (NVM)
23-
```bash
24-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
25-
```
26-
- Install Bun
27-
```bash
28-
curl -fsSL https://bun.sh/install | bash
29-
```
30-
31-
### Installing Dependencies
21+
## Installation
3222

3323
```bash
34-
nvm use
35-
bun install
24+
npm add -d @dschz/bun-plugin-solid @babel/core @babel/preset-typescript babel-preset-solid
25+
pnpm add -d @dschz/bun-plugin-solid @babel/core @babel/preset-typescript babel-preset-solid
26+
yarn add -d @dschz/bun-plugin-solid @babel/core @babel/preset-typescript babel-preset-solid
27+
bun add -d @dschz/bun-plugin-solid @babel/core @babel/preset-typescript babel-preset-solid
28+
```
29+
30+
> These are **peer dependencies**, so they must be installed manually:
31+
>
32+
> - `@babel/core`
33+
> - `@babel/preset-typescript`
34+
> - `babel-preset-solid`
35+
36+
## Plugin Options
37+
38+
> Plugin options `generate` and `hydratable` are directly derived from [`babel-preset-solid`](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/src/index.ts#L11-L18) and will be passed to it under the hood.
39+
40+
```ts
41+
type SolidPluginOptions = {
42+
/**
43+
* Whether to generate DOM or SSR-compatible output.
44+
* Defaults to "dom".
45+
*/
46+
generate?: "dom" | "ssr";
47+
48+
/**
49+
* Enables hydration code generation for SSR.
50+
* Defaults to true.
51+
*/
52+
hydratable?: boolean;
53+
54+
/**
55+
* Controls source map generation:
56+
* - false: no source maps
57+
* - true: external .map file
58+
* - "inline": base64-encoded inline source maps
59+
*
60+
* Defaults to "inline".
61+
*/
62+
sourceMaps?: boolean | "inline";
63+
64+
/**
65+
* Enable verbose debug logs during transform.
66+
* Defaults to false.
67+
*/
68+
debug?: boolean;
69+
};
3670
```
3771

38-
### Local Development Build
72+
## Usage
3973

40-
```bash
41-
bun start
74+
### 🔧 Runtime (Development) via Preload Script
75+
76+
Use this for runtime-based workflows like server-side rendering (SSR) with Elysia, Bun, or other Bun-native frameworks.
77+
78+
#### `bunPreload.ts`:
79+
80+
```ts
81+
import { plugin } from "bun";
82+
import { SolidPlugin } from "@dschz/bun-plugin-solid";
83+
84+
// The `plugin` API automatically registers a BunPlugin
85+
await plugin(
86+
SolidPlugin({
87+
generate: "ssr",
88+
hydratable: true,
89+
debug: true,
90+
}),
91+
);
4292
```
4393

44-
### Linting & Formatting
94+
#### `bunfig.toml`:
4595

46-
```bash
47-
bun run lint # checks source for lint violations
48-
bun run format # checks source for format violations
96+
```toml
97+
jsx = "solid"
98+
jsxFactory = "solid-js"
99+
preload = ["./bunPreload.ts"]
100+
```
49101

50-
bun run lint:fix # fixes lint violations
51-
bun run format:fix # fixes format violations
102+
#### Run:
103+
104+
```bash
105+
bun run server.ts
52106
```
53107

54-
### Contributing
108+
---
55109

56-
The only requirements when contributing are:
110+
### 📦 Build-Time Compilation with `Bun.build()`
57111

58-
- You keep a clean git history in your branch
59-
- rebasing `main` instead of making merge commits.
60-
- Using proper commit message formats that adhere to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
61-
- Additionally, squashing (via rebase) commits that are not [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
62-
- CI checks pass before merging into `main`
112+
Use this in production workflows to pre-compile `.tsx` or `.jsx` files to JavaScript.
113+
114+
#### `build.ts`:
115+
116+
```ts
117+
import { SolidPlugin } from "@dschz/bun-plugin-solid";
118+
119+
await Bun.build({
120+
entrypoints: ["./src/index.ts"],
121+
outdir: "./dist",
122+
target: "bun",
123+
format: "esm",
124+
plugins: [
125+
SolidPlugin({
126+
generate: "ssr",
127+
hydratable: true,
128+
sourceMaps: false, // recommended for production
129+
}),
130+
],
131+
});
132+
```

build.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const result = await Bun.build({
2+
entrypoints: ["src/index.ts"],
3+
outdir: "dist",
4+
target: "bun",
5+
format: "esm",
6+
external: ["@babel/core", "@babel/preset-typescript", "babel-preset-solid"],
7+
});
8+
9+
if (!result.success) {
10+
console.error("❌ Build failed");
11+
for (const log of result.logs) {
12+
console.error(log);
13+
}
14+
process.exit(1);
15+
}
16+
17+
console.log("✅ Build succeeded");
18+
19+
// Export empty object to treat this file as a module
20+
export {};

0 commit comments

Comments
 (0)