vite-plugin-live-reload
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -6,3 +6,15 @@ import { Plugin } from 'vite'; | ||
interface Config extends WatchOptions { | ||
/** | ||
* Whether the page should be reloaded regardless of which file is modified. | ||
* @default false | ||
*/ | ||
alwaysReload?: boolean; | ||
log?: boolean; | ||
/** | ||
* File paths will be resolved against this directory. | ||
* | ||
* @default ViteDevServer.root | ||
* @internal | ||
*/ | ||
root?: string; | ||
} | ||
@@ -9,0 +21,0 @@ declare const _default: (paths: string | readonly string[], config?: Config) => Plugin; |
@@ -20,6 +20,7 @@ 'use strict'; | ||
name: "vite-plugin-live-reload", | ||
configureServer({ws, config: {root, logger}}) { | ||
configureServer({ws, config: {root: viteRoot, logger}}) { | ||
const root = config.root || viteRoot; | ||
const reload = (path2) => { | ||
var _a; | ||
ws.send({type: "full-reload", path: path2}); | ||
ws.send({type: "full-reload", path: config.alwaysReload ? "*" : path2}); | ||
if ((_a = config.log) != null ? _a : true) { | ||
@@ -26,0 +27,0 @@ logger.info(chalk__default['default'].green(`page reload `) + chalk__default['default'].dim(getShortName(path2, root)), {clear: true, timestamp: true}); |
{ | ||
"name": "vite-plugin-live-reload", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A *very* simple live reloading plugin for vite.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# vite-plugin-live-reload | ||
A *very* simple live reloading plugin for [vite](https://github.com/vitejs/vite). | ||
# Example | ||
I use this configuration when working with [Kirby CMS](https://getkirby.com/) (assuming your Kirby site is inside a `public` folder). | ||
## Example | ||
I use this configuration when working with [Kirby CMS](https://getkirby.com/), but it works great with any backend! | ||
Note: the paths you are watching are relative to vite's root folder. | ||
Note: by default the paths are relative to Vite's root folder. | ||
```js | ||
@@ -15,5 +15,37 @@ // vite.config.js | ||
plugins: [ | ||
liveReload('public/site/(templates|snippets|controllers|models)/**/*.php'), | ||
liveReload('../site/(templates|snippets|controllers|models)/**/*.php'), | ||
] | ||
} | ||
``` | ||
## Usage | ||
Watch one or more paths: | ||
```js | ||
liveReload('my/path/**/*.php') | ||
``` | ||
```js | ||
liveReload(['my/path/**/*.php', 'my/other/path/**/*.php']) | ||
``` | ||
The plugin uses a [chokidar](https://github.com/paulmillr/chokidar) watcher. See the chokidar documentation to find out which path notations are supported. | ||
## Options | ||
### Root | ||
By default Vite's root directory is used, but you can specify your own directory: | ||
```js | ||
liveReload('my-file', { root: process.cwd() }) | ||
``` | ||
### Always reload | ||
If the modified file is an `.html` file, Vite's client only reloads the page if the browser is currently on this HTML page. With `alwaysReload` the browser is reloaded anyway. | ||
```js | ||
liveReload('my-file', { alwaysReload: true }) | ||
``` |
@@ -13,3 +13,17 @@ import { Plugin, ViteDevServer } from 'vite' | ||
interface Config extends WatchOptions { | ||
/** | ||
* Whether the page should be reloaded regardless of which file is modified. | ||
* @default false | ||
*/ | ||
alwaysReload?: boolean | ||
log?: boolean | ||
/** | ||
* File paths will be resolved against this directory. | ||
* | ||
* @default ViteDevServer.root | ||
* @internal | ||
*/ | ||
root?: string | ||
} | ||
@@ -29,5 +43,7 @@ | ||
configureServer({ ws, config: { root, logger } }: ViteDevServer) { | ||
configureServer({ ws, config: { root: viteRoot, logger } }: ViteDevServer) { | ||
const root = config.root || viteRoot | ||
const reload = (path: string) => { | ||
ws.send({ type: 'full-reload', path }) | ||
ws.send({ type: 'full-reload', path: config.alwaysReload ? '*' : path }) | ||
if (config.log ?? true) { | ||
@@ -46,2 +62,2 @@ logger.info( | ||
} | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7210
127
50