hot-reload-extension-vite
Advanced tools
Comparing version 1.0.3 to 1.0.4
import { Plugin } from 'vite'; | ||
type hotReloadExtensionViteOptions = { | ||
contentPath: string; | ||
backgroundPath: string; | ||
@@ -6,0 +5,0 @@ log?: boolean; |
@@ -544,3 +544,3 @@ "use strict"; | ||
var hotReloadExtensionVite = (options) => { | ||
const { log, contentPath, backgroundPath } = options; | ||
const { log, backgroundPath } = options; | ||
let ws = null; | ||
@@ -559,10 +559,2 @@ if (isDev) { | ||
async transform(code, id) { | ||
if (isDev && id.includes(contentPath)) { | ||
const buffer = import_fs.default.readFileSync( | ||
(0, import_path.resolve)(__dirname, "scripts/content-reload.js") | ||
); | ||
return { | ||
code: code + buffer.toString() | ||
}; | ||
} | ||
if (id.includes(backgroundPath)) { | ||
@@ -579,3 +571,3 @@ const buffer = import_fs.default.readFileSync( | ||
if (isDev && !ws) | ||
chalkLogger.red("Open tab with content script to start reloading..."); | ||
chalkLogger.red("Load extension to browser..."); | ||
if (isDev && ws) { | ||
@@ -582,0 +574,0 @@ if (log) |
@@ -8,9 +8,12 @@ "use strict"; | ||
// src/scripts/background-reload.ts | ||
chrome.runtime.onMessage.addListener((message) => { | ||
if (message === "hot-reload-message-reload-extension" /* RELOAD_EXTENSION */) { | ||
chrome.runtime.reload(); | ||
chrome.tabs.query({ active: true }).then(() => { | ||
if (isDev) { | ||
const socket = new WebSocket( | ||
`ws://localhost:${HOT_RELOAD_EXTENSION_VITE_PORT}` | ||
); | ||
socket.addEventListener("message", (event) => { | ||
if (event.data === "file-change" /* FILE_CHANGE */) { | ||
chrome.runtime.reload(); | ||
chrome.tabs.reload(); | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} |
{ | ||
"name": "hot-reload-extension-vite", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Simple vite plugin to reload the chrome extension.", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -26,3 +26,2 @@ # Hot Reload Chrome Extension - Vite Plugin | ||
log: true, | ||
contentPath: 'path/to/content-script', // src/pages/content/index.ts | ||
backgroundPath: 'path/to/background' // src/pages/background/index.ts | ||
@@ -51,3 +50,2 @@ }) | ||
| log | boolean (optional) | Logs error and info. | | ||
| contentPath | string (required) | Path to content script file. | | ||
| backgroundPath | string(required) | Path to background service worker file. | | ||
@@ -54,0 +52,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39792
11
1157
54