Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow debounce reload event #21

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ npm i -D vite-plugin-full-reload # yarn add -D vite-plugin-full-reload
Add it to your plugins in `vite.config.ts`

```ts
import { defineConfig } from 'vite'
import FullReload from 'vite-plugin-full-reload'
import { defineConfig } from "vite";
import FullReload from "vite-plugin-full-reload";

export default defineConfig({
plugins: [
FullReload(['config/routes.rb', 'app/views/**/*'])
],
})
plugins: [FullReload(["config/routes.rb", "app/views/**/*"])],
});
```

This is useful to trigger a page refresh for files that are not being imported, such as server-rendered templates.
Expand All @@ -59,35 +57,47 @@ To see which file globbing options are available, check [picomatch].
The following options can be provided:

- <kbd>root</kbd>

Files will be resolved against this directory.

__Default:__ `process.cwd()`
**Default:** `process.cwd()`

``` js
```js
FullReload('config/routes.rb', { root: __dirname }),
```
```

- <kbd>delay</kbd>

How many milliseconds to wait before reloading the page after a file change.
It can be used to offset slow template compilation in Rails.

__Default:__ `0`
**Default:** `0`

```js
FullReload('app/views/**/*', { delay: 100 })
```
FullReload("app/views/**/*", { delay: 100 });
```

- <kbd>debounce</kbd>

How many milliseconds to postpone the execution of the reload function since it's last invocation.
This is useful if you have a lot of changes in a short period of time and need to make sure that
only one `full-reload` event is sent to Vite.

**Default:** `0`

```js
FullReload("app/views/**/*", { debounce: 100 });
```

- <kbd>always</kbd>

Whether to refresh the page even if the modified HTML file is not currently being displayed.

__Default:__ `true`
**Default:** `true`

```js
FullReload('app/views/**/*', { always: false })
```
FullReload("app/views/**/*", { always: false });
```

## Acknowledgements

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"test": "vitest"
},
"dependencies": {
"debounce": "^1.2.1",
"picocolors": "^1.0.0",
"picomatch": "^2.3.1"
},
Expand All @@ -54,6 +55,7 @@
"devDependencies": {
"@antfu/eslint-config": "*",
"@types/cross-spawn": "^6.0.2",
"@types/debounce": "^1.2.1",
"@types/node": "^14.18.22",
"@types/picomatch": "^2.3.0",
"conventional-changelog-cli": "^2.2.2",
Expand Down
Loading