Skip to content

Commit 0d152b2

Browse files
authored
feat: add support for kirby serve w/ HMR plugin (#18)
* feat: add support for `kirby serve` w/ HMR plugin * feat: allow HMR refresh, abort only on HMR reload * feat: rename module entry to _index.mjs makes it clearer that module entries are an internal, dev-only feature * docs: update examples to include serve script * feat: reload on PHP change in serve mode * feat: live-reload via CLI arg, CLI help, refactor * fix: only call server.close() if still listening * fix: set server.origin to serve assets in dev mode depends on vuejs/vue#12732 * fix: always pass array to vite-full-reload-plugin ElMassimo/vite-plugin-full-reload#9 * feat: specify port via cli instead of kirbyup conf * refactor: update reload-plugin, remove workaround * feat: make sure index.dev.mjs is gone after build * feat: set index.dev.mjs location with --out-dir * docs: update README for serve command * docs: capitalize "panel" * refactor: inline getViteConfig() type * fix: only handle SIGINT, implemented like vite
1 parent f2be3f0 commit 0d152b2

File tree

11 files changed

+534
-293
lines changed

11 files changed

+534
-293
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

README.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The fastest and leanest way to bundle your Kirby Panel plugins. No configuration
88

99
- 🍂 Lightweight, robust and tested
1010
- ⚡️ Fast compilation with Vite/esbuild
11-
- 🔍 Watch mode
11+
- 🔄 Hot Module Replacement and Watch mode
1212
- \*️⃣ `kirbyup.import` to [auto-import blocks & fields](#auto-import-blocks-and-fields)
1313
- 🎒 [PostCSS support](#postcss)
1414
- 🧭 [Path resolve aliases](#path-resolve-aliases)
@@ -36,7 +36,7 @@ If you want to use kirbyup right away, there is no need to install it. Simply ca
3636
```json
3737
{
3838
"scripts": {
39-
"dev": "npx -y kirbyup src/index.js --watch",
39+
"dev": "npx -y kirbyup serve src/index.js",
4040
"build": "npx -y kirbyup src/index.js"
4141
}
4242
}
@@ -55,7 +55,7 @@ Example package configuration:
5555
```json
5656
{
5757
"scripts": {
58-
"dev": "kirbyup src/index.js --watch",
58+
"dev": "kirbyup serve src/index.js",
5959
"build": "kirbyup src/index.js"
6060
},
6161
"devDependencies": {
@@ -70,31 +70,21 @@ Global installation is supported as well, but not recommended.
7070

7171
### Development
7272

73-
Rebuild the Panel plugin on any file changes:
73+
Start a development server for the Panel plugin:
7474

7575
```bash
76-
kirbyup src/index.js --watch
76+
kirbyup serve src/index.js
7777
```
7878

79-
You can also specify the directories to be watched. By default, if no path is specified, kirbyup watches the directory specified by the input file (`src` for the example above).
80-
81-
```bash
82-
kirbyup src/index.js --watch src
83-
```
84-
85-
You can specify more than a single directory:
86-
87-
```bash
88-
kirbyup src/index.js --watch src --watch libs
89-
```
79+
This creates `./index.dev.mjs`, telling Kirby to load the development version of the plugin from the dev server started by `kirbyup serve`, enhanced by features like hot module replacement and auto-reload.
9080

9181
### Production
9282

9383
```bash
9484
kirbyup src/index.js
9585
```
9686

97-
The final panel plugin will be bundled, minified, and written into the current directory as `./index.js`.
87+
The final panel plugin will be bundled, minified, and written into the current directory as `./index.js` and `./index.css`.
9888

9989
## Built-in Features
10090

@@ -222,15 +212,38 @@ For a complete list of options, take a look at the [Vite configuration options](
222212

223213
## Options
224214

225-
> Inspect all available options with `kirbyup --help`.
215+
> Inspect all available options with `kirbyup --help` and `kirbyup serve --help`.
216+
217+
### `kirbyup <input>`
226218

227-
### `--out-dir`
219+
##### `--out-dir <dir>`
228220

229221
The output directory to save the processed code into. Defaults to the current working directory.
230222

231-
### `--watch`
223+
##### `--watch [path]`
224+
225+
Enables watch mode. If no path is specified, kirbyup watches the folder of the input file. Repeat `--watch` for multiple paths.
226+
227+
### `kirbyup serve <input>`
228+
229+
##### `--port <port>`
230+
231+
The port for the development server to run on. Defaults to `5177`.
232+
233+
##### `--out-dir <dir>`
234+
235+
The output directory where the plugin file read by Kirby is saved. Defaults to the project root.
236+
237+
##### `--watch <path>`
238+
239+
Specifies additional files that should be watched for changes, with changes causing the page to reload. Repeat `--watch` for multiple paths.
240+
241+
> 💡 By default, kirbyup will watch all PHP files (`./**/*.php`) in the plugin directory and reload the page if it detects changes. Using `--watch` to set your own path overrides this setting, so you need to add the PHP glob explicitly if you want to keep the behavior: `--watch ./my/files/* --watch ./**/*.php`
242+
243+
##### `--no-watch`
244+
245+
Disables the default behavior of watching all PHP files for changes.
232246

233-
Sets the watch mode. If no path is specified, kirbyup watches the folder of the input file. Repeat `--watch` for multiple paths.
234247

235248
## Credits
236249

examples/eslint-and-prettier/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"scripts": {
4-
"dev": "kirbyup src/index.js --watch",
4+
"dev": "kirbyup serve src/index.js",
55
"build": "kirbyup src/index.js",
66
"lint": "eslint \"src/**/*.{js,vue}\"",
77
"lint:fix": "npm run lint -- --fix",

examples/tailwindcss/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"scripts": {
4-
"dev": "kirbyup src/index.js --watch",
4+
"dev": "kirbyup serve src/index.js",
55
"build": "kirbyup src/index.js"
66
},
77
"devDependencies": {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kirbyup",
33
"version": "1.3.2",
4-
"packageManager": "pnpm@7.6.0",
4+
"packageManager": "pnpm@7.8.0",
55
"description": "Zero-config bundler for Kirby Panel plugins",
66
"author": {
77
"name": "Johann Schopplich",
@@ -74,6 +74,7 @@
7474
"cac": "^6.7.12",
7575
"chokidar": "^3.5.3",
7676
"consola": "^2.15.3",
77+
"detect-package-manager": "^2.0.1",
7778
"magic-string": "^0.26.2",
7879
"pathe": "^0.3.3",
7980
"perfect-debounce": "^0.1.3",
@@ -85,6 +86,7 @@
8586
"sass": "^1.54.1",
8687
"unconfig": "^0.3.5",
8788
"vite": "^3.0.4",
89+
"vite-plugin-full-reload": "^1.0.4",
8890
"vue": "^2.7.8"
8991
},
9092
"devDependencies": {

0 commit comments

Comments
 (0)