Skip to content

Commit 86e0c96

Browse files
Merge pull request #87 from preactjs/devtools-css
Only inject devtools css when Preact was detected
2 parents 31a6ba6 + 7aaf11c commit 86e0c96

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

src/shells/chrome/manifest.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
"run_at": "document_start"
3535
}
3636
],
37-
"web_accessible_resources": ["installHook.css", "panel.html", "devtools.html"]
37+
"web_accessible_resources": [
38+
"preact-devtools-page.css",
39+
"panel.html",
40+
"devtools.html"
41+
]
3842
}

src/shells/edge/manifest.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
"run_at": "document_start"
3535
}
3636
],
37-
"web_accessible_resources": ["installHook.css", "panel.html", "devtools.html"]
37+
"web_accessible_resources": [
38+
"preact-devtools-page.css",
39+
"panel.html",
40+
"devtools.html"
41+
]
3842
}

src/shells/firefox/manifest.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@
3838
"run_at": "document_start"
3939
}
4040
],
41-
"web_accessible_resources": ["installHook.css", "panel.html", "devtools.html"]
41+
"web_accessible_resources": [
42+
"preact-devtools-page.css",
43+
"panel.html",
44+
"devtools.html"
45+
]
4246
}

src/shells/shared/initClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ window.addEventListener("message", ev => {
1313
hasPreact: true,
1414
}),
1515
);
16+
17+
injectStyles(chrome.runtime.getURL("preact-devtools-page.css"));
1618
}
1719
});
1820

@@ -42,5 +44,4 @@ if (document.contentType === "text/html") {
4244
//
4345
// The string "CODE_TO_INJECT" will be replaced by our build tool.
4446
inject(`;(${"CODE_TO_INJECT"}(window))`, "code");
45-
injectStyles(chrome.runtime.getURL("installHook.css"));
4647
}

tools/build.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const archiver = require("archiver");
22
const fs = require("fs");
33
const path = require("path");
4-
const rimraf = require("rimraf");
54

65
const browser = process.env.BROWSER;
76

87
// Manually bundle injection code to make sure it runs before everything else
9-
const source = path.join(__dirname, "..", "dist", browser, "installHook.js");
10-
const target = path.join(__dirname, "..", "dist", browser, "initClient.js");
8+
const dist = path.join(__dirname, "..", "dist", browser);
9+
const source = path.join(dist, "installHook.js");
10+
const target = path.join(dist, "initClient.js");
1111
const hook = fs
1212
.readFileSync(source, "utf8")
1313
.replace(/\(function \(\) \{/g, "function install() {")
@@ -33,6 +33,12 @@ fs.writeFileSync(target, targetFile);
3333
// Now that we inlined installHook.js we can delete it
3434
fs.unlinkSync(source);
3535

36+
// Rename injected css file so users understand where it's coming from.
37+
fs.renameSync(
38+
path.join(dist, "installHook.css"),
39+
path.join(dist, "preact-devtools-page.css"),
40+
);
41+
3642
// Package extension
3743
const output = fs.createWriteStream(__dirname + `/../dist/${browser}.zip`);
3844
const archive = archiver("zip", { zlib: { level: 9 } });

0 commit comments

Comments
 (0)