Automatically reloads the browser when files are modified while the hexo-server is running. Inspired by hexo-browsersync.
hexo-browser-reloader-websocket
is transparent. Once installed, just run hexo-server
.
Warning
Please DO NOT USE in production (It means do not run hexo-server
in production).
- Please use this plugin only for development (local environment).
- Hexo is a static site generator. It is not intended to run
hexo-server
in production. - This plugin does not encrypt between the WebSocket server and client.
npm i hexo-browser-reloader-websocket
Example (Defalut):
# _config.yml
browser_reloader_websocket:
enable: true
server:
port: 4001
notification:
message: "reloadBrowser"
wait:
min: 150 # ms
autoCalc:
enable: true
coefficient: 1.0
key | type | description | default |
---|---|---|---|
enable |
boolean | Manage enable or disable this plugin. | true |
port |
number | WebSocket server's port. | 4001 |
message |
string | WebSocket message event data. | reloadBrowser |
wait.min |
number | Minimum waiting time for reload browser after detecting file changes. Pleasse see About wait time. | 150 |
wait.autoCalc.enable |
boolean | Calculate the waiting time for the reload browser after detecting file changes based on the number of routes. Pleasse see About wait time. | true |
wait.autoCalc.coefficient |
number | Coefficient for calculate wait time if autoCalc is enabled. | 1.0 |
Reloading the browser by this plugin may be faster than the hexo-server's router updating if there are few routes or a lot of routes. The router updating speed depends on the number of post, pages, assets, tags, categories...etc. Also it depends on theme, plugins and machine power etc.
The wait
option for resolve this, wait a little bit after file change detection before starting the browser reload.
If the wait.autoCalc.enabled
option is true
, the plugin calculates the waiting time based on the number of routes. Below is a calculation formula.
// calculation formula
(<number of routes> / 10) * <autoCalc.coefficient> = wait(ms)
// example
(1200 / 10) * 0.9 = 108ms
Please see logger docs if you need.