
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
extension-hmr-reload-plugin
Advanced tools
A Webpack5 plugin used for browser extension development, which can reload the extension automatically when use hmr.
This is a hot module replacement (HMR) Webpack plugin for developing browser extensions (Chrome/Edge/Firefox). With the advent of AI and modern browser functionalities, AI-based browser extension applications are emerging. If you are interested in browser extension development and Webpack, this might help you.
background
and content-script
in development mode, eliminating the need to manually reload the extension frequently.webextension-polyfill
for compatibility across different browsers.Webpack 5 and scaffolds based on Webpack 5. If your project uses Webpack 4.
When developing browser extensions locally, due to the nature of local installation and debugging and browser restrictions, background
and content-script
do not automatically update, even if the local files have indeed been updated. This requires developers to manually refresh the extension files (background) and the web page (content-script) in the browser.
This plugin provides the capability to automatically reload the extension and refresh the related web pages.
In Webpack:
const { HmrReloadPlugin } = require("extension-hmr-reload-plugin")
module.exports = {
...
plugins: [
...
new HmrReloadPlugin(),
]
}
The port for the plugin server, default is 4001
.
An array of filenames that need to inject the hot reload script. Check the filenames in your output directory, for example:
# your outputdir
output
- background.js
- background.xxx.js
- content
- content-script.js
- sidepanel.js
- ...
You can fill in the configuration like this, the filenames will be matched based on inclusion, corresponding to background reload and webpage refresh:
new HmrReloadPlugin({
injections: {
reload: ['background.js'],
refresh: ['content-script'],
},
}),
string
The directory to watch for file changes. When you change a file and save it, it will first trigger compilation and then trigger the plugin hook. The default value is the same-level path of the configuration file ./
.
string[]
The directories to trigger reload after file changes. The default value is ['background', 'content']
. Adjust it according to your project structure. Here is an example project structure:
# your project
src
- background
- ...
webpack.config.js
Example configuration:
// plugin options
new HmrReloadPlugin({
injections: {
reload: ['background.js'],
refresh: ['content-script.js'],
},
listenDir: path.resolve('./src'),
reloadDir: ['background', 'content']
})
// your project
output
- background.js
- content-script.js
- sidepanel.js
- ...
src
- background
- main.js
- content
- main.js
- sidepanel
- ...
webpack.config.js
The author's energy is limited and has only implemented the Webpack 5 plugin. If you are using other tools like Vite or want to adapt it to Webpack 3/4, feel free to contact the author and contribute your open-source power.
https://github.com/GITfsj/ExtensionHmrReloadPlugin/blob/main/README.md
npm install
npm run build
You can directly install to use through NPM
https://www.npmjs.com/package/extension-hmr-reload-plugin?activeTab=readme
npm install --save-dev extension-hmr-reload-plugin
FAQs
A Webpack5 plugin used for browser extension development, which can reload the extension automatically when use hmr.
The npm package extension-hmr-reload-plugin receives a total of 0 weekly downloads. As such, extension-hmr-reload-plugin popularity was classified as not popular.
We found that extension-hmr-reload-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.