|
2 | 2 |
|
3 | 3 | [](https://www.npmjs.com/package/unplugin-solid) |
4 | 4 |
|
| 5 | +Solid 2 compilation for Vite, Rollup, Rolldown, webpack, Rspack, esbuild, and Astro, powered by unplugin. |
| 6 | + |
5 | 7 | ## 📦 Installation |
6 | 8 |
|
7 | 9 | ```bash |
8 | | -$ npm install -D unplugin-solid |
9 | | -$ yarn add -D unplugin-solid |
10 | | -$ pnpm add -D unplugin-solid |
| 10 | +npm install -D unplugin-solid |
| 11 | +npm install solid-js@^2.0.0-rc.9 @solidjs/web@^2.0.0-rc.9 |
| 12 | +``` |
| 13 | + |
| 14 | +For TypeScript projects, preserve JSX for the plugin and use the web runtime's JSX types: |
| 15 | + |
| 16 | +```json |
| 17 | +{ |
| 18 | + "compilerOptions": { |
| 19 | + "jsx": "preserve", |
| 20 | + "jsxImportSource": "@solidjs/web" |
| 21 | + } |
| 22 | +} |
11 | 23 | ``` |
12 | 24 |
|
13 | 25 | ## 🚀 Usage |
14 | 26 |
|
| 27 | +Add the adapter for your build tool to its configuration. Vite and Astro require Vite 8 or 9. |
| 28 | + |
15 | 29 | <details> |
16 | | -<summary>Vite</summary><br> |
| 30 | +<summary>Vite</summary> |
17 | 31 |
|
18 | 32 | ```ts |
19 | 33 | // vite.config.ts |
20 | 34 | import Solid from "unplugin-solid/vite"; |
| 35 | +import { defineConfig } from "vite"; |
21 | 36 |
|
22 | 37 | export default defineConfig({ |
23 | | - plugins: [Solid({/* options */})], |
| 38 | + plugins: [Solid()], |
24 | 39 | }); |
25 | 40 | ``` |
26 | 41 |
|
27 | | -<br></details> |
| 42 | +</details> |
28 | 43 |
|
29 | 44 | <details> |
30 | | -<summary>Rollup</summary><br> |
| 45 | +<summary>Rollup</summary> |
31 | 46 |
|
32 | | -```ts |
| 47 | +```js |
33 | 48 | // rollup.config.js |
34 | 49 | import Solid from "unplugin-solid/rollup"; |
35 | 50 |
|
36 | 51 | export default { |
37 | | - plugins: [ |
38 | | - Solid({/* options */}), |
39 | | - // other plugins |
40 | | - ], |
| 52 | + plugins: [Solid()], |
41 | 53 | }; |
42 | 54 | ``` |
43 | 55 |
|
44 | | -<br></details> |
| 56 | +</details> |
45 | 57 |
|
46 | 58 | <details> |
47 | | -<summary>Rolldown</summary><br> |
| 59 | +<summary>Rolldown</summary> |
48 | 60 |
|
49 | | -```ts |
| 61 | +```js |
50 | 62 | // rolldown.config.js |
51 | 63 | import Solid from "unplugin-solid/rolldown"; |
52 | 64 |
|
53 | 65 | export default { |
54 | | - plugins: [ |
55 | | - Solid({/* options */}), |
56 | | - // other plugins |
57 | | - ], |
| 66 | + plugins: [Solid()], |
58 | 67 | }; |
59 | 68 | ``` |
60 | 69 |
|
61 | | -<br></details> |
| 70 | +</details> |
62 | 71 |
|
63 | 72 | <details> |
64 | | -<summary>Webpack</summary><br> |
| 73 | +<summary>webpack</summary> |
| 74 | + |
| 75 | +```js |
| 76 | +// webpack.config.cjs |
| 77 | +const Solid = require("unplugin-solid/webpack"); |
65 | 78 |
|
66 | | -```ts |
67 | | -// webpack.config.js |
68 | 79 | module.exports = { |
69 | | - /* ... */ |
70 | | - plugins: [require("unplugin-solid/webpack")({/* options */})], |
| 80 | + plugins: [Solid()], |
71 | 81 | }; |
72 | 82 | ``` |
73 | 83 |
|
74 | | -<br></details> |
| 84 | +</details> |
75 | 85 |
|
76 | 86 | <details> |
77 | | -<summary>esbuild</summary><br> |
| 87 | +<summary>Rspack</summary> |
78 | 88 |
|
79 | | -```ts |
80 | | -// esbuild.config.js |
| 89 | +```js |
| 90 | +// rspack.config.cjs |
| 91 | +const Solid = require("unplugin-solid/rspack"); |
| 92 | + |
| 93 | +module.exports = { |
| 94 | + plugins: [Solid()], |
| 95 | +}; |
| 96 | +``` |
| 97 | + |
| 98 | +</details> |
| 99 | + |
| 100 | +<details> |
| 101 | +<summary>esbuild</summary> |
| 102 | + |
| 103 | +```js |
| 104 | +// build.mjs |
81 | 105 | import { build } from "esbuild"; |
| 106 | +import Solid from "unplugin-solid/esbuild"; |
82 | 107 |
|
83 | | -build({ |
84 | | - /* ... */ |
85 | | - plugins: [require("unplugin-solid/esbuild")({/* options */})], |
| 108 | +await build({ |
| 109 | + entryPoints: ["src/index.tsx"], |
| 110 | + bundle: true, |
| 111 | + outdir: "dist", |
| 112 | + plugins: [Solid()], |
86 | 113 | }); |
87 | 114 | ``` |
88 | 115 |
|
89 | | -<br></details> |
| 116 | +</details> |
90 | 117 |
|
91 | 118 | <details> |
92 | | -<summary>Astro</summary><br> |
| 119 | +<summary>Astro</summary> |
93 | 120 |
|
94 | | -```ts |
| 121 | +```js |
95 | 122 | // astro.config.mjs |
| 123 | +import { defineConfig } from "astro/config"; |
96 | 124 | import Solid from "unplugin-solid/astro"; |
97 | 125 |
|
98 | 126 | export default defineConfig({ |
99 | | - integrations: [Solid({/* options */})], |
| 127 | + integrations: [Solid({})], |
100 | 128 | }); |
101 | 129 | ``` |
102 | 130 |
|
103 | | -<br></details> |
| 131 | +</details> |
| 132 | + |
| 133 | +## ⚙️ Options |
| 134 | + |
| 135 | +All adapters use the native Solid compiler by default. Pass `compiler: "babel"` to use the Babel compiler: |
| 136 | + |
| 137 | +```ts |
| 138 | +Solid({ compiler: "babel" }); |
| 139 | +``` |
| 140 | + |
| 141 | +Use `solid` to configure JSX compilation and `babel` to add Babel plugins or presets. With the native compiler, custom Babel transforms run before JSX compilation. |
| 142 | + |
| 143 | +Vite and Astro support refresh, SSR compilation, and experimental TSRX. Compiling TSRX with the Babel backend also requires `@tsrx/[email protected]`. Use `refresh: { disabled: true }` to disable refresh, or `observe: true` to select Solid’s observable runtime builds. |
| 144 | + |
| 145 | +The other adapters support JSX compilation options. Set `ssr: true` when compiling a server bundle and `dev: true` to enable compiler development output. |
104 | 146 |
|
105 | 147 | ## 📝 License |
106 | 148 |
|
|
0 commit comments