1.1.1 • Published 1 month ago
ws-reload-plugin v1.1.1
wsReloadPlugin 中文
Upate: Fix the bug that the new version of the chrome kernel does not refresh
a webpack auto reload plugin for chrome extension v3 developers
The run steps:
- 1.create a websocket server and client in node,when everytime compiler is finished,send message to content client(why not service worker? it will sleep, it needs event driven)
- 2.create a websocket client in content to receive message, then send command to service worker
- 3.service worker listen the command to reload runtime and tab
in your webpack.config.js, add the following code
// the parameter: { port = 7777 }
const { wsAutoReloadPlugin } = require('ws-reload-plugin')
plugins: [new wsAutoReloadPlugin()]
in your content.js(content_scripts), add the following code
// the parameter: {reconnectTime = 20, port = 7777, message = 'compiler'}
// the interval of each reconnect is 3 seconds, it will reconnect 20 times by default
const { createWsConnect } = require('ws-reload-plugin')
createWsConnect({})
// or use ES module
import { createWsConnect } from 'ws-reload-plugin'
createWsConnect({})
in your background.js(service_worker), add the following code
// the parameters and default values:: bgdListenMsg(yourMsg = 'compiler')
// yourMsg must be as same as parameters.message in createWsConnect({})
const { bgdListenMsg } = require('ws-reload-plugin')
bgdListenMsg()
// or use ES module
import { bgdListenMsg } from 'ws-reload-plugin'
bgdListenMsg()