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.
Files changed (2) hide show
  1. package/README.md +38 -33
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # vite-plugin-hyperapp
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
- ## Quickstart
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
- This will set you up with all the necessary configuration described below.
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
- To manually set up your vite-project for use with Hyperapp, install this plugin:
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
- And add it to the plugins in your `vite.config.js`:
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
- You can pass an options object to the plugin, e.g:
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. It only works if the module follows these two rules:
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
- - It must contain:
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
- import {..., app [as something],...} from 'hyperapp'
60
+ //vite.config.js
61
+ export default defineConfig({
62
+ plugins: [hyperapp({
63
+ dispatchExport: "myDispatchAlias"
64
+ })],
65
+ })
67
66
  ```
68
67
 
69
- - It must _export_ a _named_ (not default) constant/variable `dispatch`, which should be the function retuned from calling `app({...})`.
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
- And if you'd rather use Vite's HMR api directly, or forego HMR entirely, you can use the plugin option: `hmr: false`
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
- Generally, in order to set up SSR in your project you can follow Vite's instructions here: [https://vitejs.dev/guide/ssr.html#server-side-rendering](https://vitejs.dev/guide/ssr.html#server-side-rendering)
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
- Here are some specifics you'll need to know when using hyperapp and this plugin:
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
- Note: 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.
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
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-hyperapp",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "description": "Plugin and helpers for using Hyperapp with Vite",
6
6
  "main": "index.js",