hexo-workbox-build
A hexo plugin to run workbox-build and provide convenient features of PWA and service worker.
Feature
- run workbox-build via passing through your custom options. (generateSW mode or injectManifest mode)
- generate the script which using to register service-worker.
- reference the register script into html.
This plugin doesn't provide PWA support ready out of the box.
You need to know how to use workbox-build, configurate workbox strategy.
Install
pnpm add hexo-workbox-build
# npm i hexo-workbox-build
Configuration
Default Configuration
hexo_workbox_build:
enable: false
WB_runWorkboxBuild: true
WB_swDest: ""
WB_generateSWOptionsPath: ""
WB_injectManifestOptionsPath: ""
REG_generateRegister: true
REG_registerScriptDest: "registerSW.js"
# REG_registerScriptNjkPath: "" # default to internal nunjucks template
REG_injector: true
REG_injectorNjkString: '<script defer src="{{ REG_registerScriptDest }}"></script>'
Example Configuration
hexo_workbox_build:
enable: true
WB_runWorkboxBuild: true
WB_swDest: "sw.js"
WB_generateSWOptionsPath: "workbox/genSWOption.js"
# WB_injectManifestOptionsPath: "workbox/injMfOption.js"
REG_generateRegister: true
# REG_registerScriptDest: 'registerSW.js'
# REG_registerScriptNjkPath: "" # default to internal nunjucks template
REG_injector: true
# REG_injectorNjkString: '<script defer src="{{ REG_registerScriptDest }}"></script>'
Options
enable or disable this plugin
| option name | value type | default value | note |
|---|---|---|---|
enbale |
boolean | false |
Control whether to enable hexo-workbox-build. |
ralated to workbox-build
| option name | value type | default value | note |
|---|---|---|---|
WB_runWorkboxBuild |
boolean | true |
Control whether to run worlbox-build. |
WB_swDest |
string | "" | Specify the name and path of service-worker that worlbox-build generated. (relative to public dir). equal to the swDest option in worlbox-build. |
WB_generateSWOptionsPath |
string | "" | Need WB_swDest setting.Specify the path of a js file. (relative to your hexo dir), which use default exports the arguments of generatesw-mode of worlbox-build. |
WB_injectManifestOptionsPath |
string | "" | Need WB_swDest generatesw-mode setting.Specify the path of a js file. (relative to your hexo dir), which use default exports the arguments of injectmanifest-mode of worlbox-build |
Note:
injectmanifest-modedepend on a builtsw.js.It means you need to run
generatesw-modefirst inhexo-workbox-build.
ralated to register service worker
generate the code of registering service-worker
| option name | value type | default value | note |
|---|---|---|---|
REG_generateRegister |
boolean | true |
Control whether to generater a javascript, which is use to register service-worker. |
REG_registerScriptDest |
string | registerSW.js |
Need WB_swDest.Specify the path of the above javascript code generated. (relative to public dir) |
REG_registerScriptNjkPath |
string | "" | path of a nunjucks template of the javascript. (relative to your hexo dir) Default template: ./assets/registerScript.njk |
insert the registering code into html
| option name | value type | default value | note |
|---|---|---|---|
REG_injector |
boolean | true |
Control whether to Inject the above javascript code into html <script>. You can use REG_injectorNjkString to custom it. |
REG_injectorNjkString |
string | <script defer src="{{ REG_registerScriptDest }}"></script> |
Custom the <scripts> string. |