vite-plugin-hyperapp 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
# Vite Hyperapp Plugin & Starter
|
|
2
3
|
|
|
3
4
|
Use vite as a dev-server and bundler for your hyperapp projects. Supports:
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ Use vite as a dev-server and bundler for your hyperapp projects. Supports:
|
|
|
6
7
|
- Hot module reloading (HMR)
|
|
7
8
|
- Server-side rendering (SSR)
|
|
8
9
|
|
|
9
|
-
##
|
|
10
|
+
## Get Started
|
|
10
11
|
|
|
11
12
|
To get up and running with Hyperapp and Vite in a few seconds, use [create-vite-hyperapp](https://github.com/zaceno/create-vite-hyperapp):
|
|
12
13
|
|
|
@@ -14,19 +15,21 @@ To get up and running with Hyperapp and Vite in a few seconds, use [create-vite-
|
|
|
14
15
|
> npm create vite-hyperapp
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
> Use `npm create vite-hyperapp -- --help` for some command line options.
|
|
19
|
+
|
|
20
|
+
The starter will ask you for a folder in which to scaffold the project, and it will also ask if you would like to use typescript and/or SSR.
|
|
18
21
|
|
|
19
|
-
## Config
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
### Manual setup
|
|
24
|
+
|
|
25
|
+
In case you want to install manually, you need a project folder with `vite` installed, and a `vite.config.js` ready to go. Then you can install the vite-plugin for hyperapp, and enable it in the config:
|
|
22
26
|
|
|
23
27
|
```sh
|
|
24
28
|
> npm install vite-plugin-hyperapp
|
|
25
29
|
```
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```
|
|
31
|
+
```js
|
|
32
|
+
// vite.config.js
|
|
30
33
|
import { defineConfig } from "vite"
|
|
31
34
|
import hyperapp from "vite-plugin-hyperapp"
|
|
32
35
|
|
|
@@ -34,23 +37,11 @@ export default defineConfig({
|
|
|
34
37
|
plugins: [hyperapp()],
|
|
35
38
|
})
|
|
36
39
|
```
|
|
40
|
+
> Options are passed as an object to `hyperapp({...})`. Available options described below.
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
plugins: [hyperapp({
|
|
42
|
-
optionA: 'foo',
|
|
43
|
-
optionB: 'bar',
|
|
44
|
-
})]
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
...but most of the time you won't need it. See "Hot-module-reloading" below for some options that might be relevant.
|
|
48
|
-
|
|
49
|
-
## Typescript
|
|
50
|
-
|
|
51
|
-
To make sure you get proper typing support in your `.tsx` files, make sure to add these compiler options to your `tsconfig.json`:
|
|
42
|
+
Additionally, if you want typescript/TSX support, please add the following options to `compilerOptions` in your `tsconfig.json`:
|
|
52
43
|
|
|
53
|
-
```
|
|
44
|
+
```json
|
|
54
45
|
/* Necessary for tsx to work with vite-plugin-hyperapp*/
|
|
55
46
|
"jsx": "preserve",
|
|
56
47
|
"jsxImportSource": "vite-plugin-hyperapp"
|
|
@@ -58,25 +49,38 @@ To make sure you get proper typing support in your `.tsx` files, make sure to ad
|
|
|
58
49
|
|
|
59
50
|
## Hot-module-reloading (HMR)
|
|
60
51
|
|
|
61
|
-
For hot-module-reloading to work, the plugin injects some code in the module where you initiate the app.
|
|
52
|
+
For hot-module-reloading to work, the plugin injects some code in the module where you initiate the app. In order for this to work, the app-initiation module must follow these two rules:
|
|
53
|
+
|
|
54
|
+
1. It must import `app` from `"hyperapp"` using named imports (i.e. with `{..app...}`, not `*`
|
|
55
|
+
2. The dispatch function returned from the app-call must be exported as a _named_ (not default) export.
|
|
62
56
|
|
|
63
|
-
|
|
57
|
+
By default, HMR expects the exported dispatch function to be named `dispatch`. If you choose to name it something else, let the plugin know by providing it to the plugin options:
|
|
64
58
|
|
|
65
59
|
```js
|
|
66
|
-
|
|
60
|
+
//vite.config.js
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
plugins: [hyperapp({
|
|
63
|
+
dispatchExport: "myDispatchAlias"
|
|
64
|
+
})],
|
|
65
|
+
})
|
|
67
66
|
```
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
If you'd rather name the `dispatch` export something else, you can tell the plugin the name you're using as a plugin option: `dispatchExport: "myPreferredName"`
|
|
68
|
+
And if you'd rather use Vite's HMR api directly, or forego HMR entirely, you can use set that as an option in the plugin as well:
|
|
72
69
|
|
|
73
|
-
|
|
70
|
+
```js
|
|
71
|
+
//vite.config.js
|
|
72
|
+
export default defineConfig({
|
|
73
|
+
plugins: [hyperapp({
|
|
74
|
+
hmr: false
|
|
75
|
+
})],
|
|
76
|
+
})
|
|
77
|
+
```
|
|
74
78
|
|
|
75
79
|
## Server-side Rendering (SSR)
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
Server side rendering with Vite in general is described here: https://vitejs.dev/guide/ssr.html#server-side-rendering Below are some important details specific to Hyperapp and this plugin.
|
|
78
82
|
|
|
79
|
-
|
|
83
|
+
> When you use `npm create vite-hyperapp` to scaffold a project with SSR, these details are set up for you. But they're useful to be aware of as you build out your app.
|
|
80
84
|
|
|
81
85
|
### Redering your initial app to raw html
|
|
82
86
|
|
|
@@ -94,7 +98,7 @@ export async function render() {
|
|
|
94
98
|
|
|
95
99
|
`renderApp` is an async function that takes the same options object as `hyperapp.app` - except the `node` option - and returns a promise which resolves to the html-string.
|
|
96
100
|
|
|
97
|
-
|
|
101
|
+
> It is important that the server-entry module has `import ... from 'vite-plugin-hyperapp/ssr'` somewhere in it, in order for HMR to continue working on SSR enabled apps.
|
|
98
102
|
|
|
99
103
|
### Mountpoint defined by the view
|
|
100
104
|
|
|
@@ -136,3 +140,4 @@ Then you _DON'T_ add your ssr outlet like this:
|
|
|
136
140
|
```
|
|
137
141
|
|
|
138
142
|
And you make sure that the root-node of your view has `id="app"`.
|
|
143
|
+
|