Skip to content

Commit

Permalink
style nits
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Aug 19, 2024
1 parent 48ec449 commit aa89ea7
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions esbuild/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,34 @@ export const getDevOptions = ({
function liveReloadPlugin({ target }: { target: Target }): ESBuildPlugin {
const port = SERVE_PORTS[target]
const reloadScriptBackground = `
new EventSource('http://localhost:${port}/esbuild').addEventListener('change', async (ev) => {
const browser = 'browser' in globalThis ? globalThis.browser : globalThis.chrome;
const data = JSON.parse(ev.data)
if (data.added.some(s => s.includes('background.js')) || data.updated.some(s => s.includes('background.js'))) {
console.warn(">>>>>>>> reloading background...")
await browser.runtime.reload();
new EventSource("http://localhost:${port}/esbuild").addEventListener(
"change",
async (ev) => {
const browser = "browser" in globalThis ? globalThis.browser : globalThis.chrome;
const data = JSON.parse(ev.data);
if (
data.added.some(s => s.includes("background.js")) ||
data.updated.some(s => s.includes("background.js"))
) {
console.warn(">>>>>>>> reloading background...");
await browser.runtime.reload();
}
}
});`
);`

const reloadScriptPopup = `
new EventSource('http://localhost:${port}/esbuild').addEventListener('change', (ev) => {
const data = JSON.parse(ev.data)
if (data.added.some(s => s.includes('popup.js')) || data.updated.some(s => s.includes('popup.js'))) {
globalThis.location.reload()
new EventSource("http://localhost:${port}/esbuild").addEventListener(
"change",
(ev) => {
const data = JSON.parse(ev.data);
if (
data.added.some(s => s.includes("popup.js")) ||
data.updated.some(s => s.includes("popup.js"))
) {
globalThis.location.reload();
}
}
});`
);`

return {
name: 'live-reload',
Expand Down

0 comments on commit aa89ea7

Please sign in to comment.