@crxjs/vite-plugin 2.0.0-beta.19 → 2.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +27 -8
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -348,7 +348,8 @@ const pluginBackground = () => {
|
|
|
348
348
|
};
|
|
349
349
|
} else {
|
|
350
350
|
manifest.background = {
|
|
351
|
-
scripts: [this.getFileName(refId)]
|
|
351
|
+
scripts: [this.getFileName(refId)],
|
|
352
|
+
type: "module"
|
|
352
353
|
};
|
|
353
354
|
}
|
|
354
355
|
return manifest;
|
|
@@ -1409,9 +1410,9 @@ const pluginHtmlInlineScripts = () => {
|
|
|
1409
1410
|
};
|
|
1410
1411
|
};
|
|
1411
1412
|
|
|
1412
|
-
var
|
|
1413
|
+
var loadingPageScript = "const VITE_URL = \"http://localhost:%PORT%\";\ndocument.body.innerHTML = `\n<div\n id=\"app\"\n style=\"\n border: 1px solid #ddd;\n padding: 20px;\n border-radius: 5px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n \"\n >\n <h1 style=\"color: #333\">Vite Dev Mode</h1>\n <p style=\"color: #666\">\n Cannot connect to the Vite Dev Server on <a href=\"${VITE_URL}\">${VITE_URL}</a>\n </p>\n <p style=\"color: #666\">\n Double-check that Vite is working and reload the extension.\n </p>\n <p style=\"color: #666\">\n This page will close when the extension reloads.\n </p>\n <button\n style=\"\n padding: 10px 20px;\n border: none;\n background-color: #007bff;\n color: #fff;\n border-radius: 5px;\n cursor: pointer;\n \"\n >\n Reload Extension\n </button>\n </div>`;\ndocument.body.querySelector(\"button\")?.addEventListener(\"click\", () => {\n chrome.runtime.reload();\n});\nlet tries = 0;\nlet ready = false;\ndo {\n try {\n await fetch(VITE_URL);\n ready = true;\n } catch {\n const timeout = Math.min(100 * Math.pow(2, ++tries), 5e3);\n console.log(`[CRXJS] Vite Dev Server is not available on ${VITE_URL}`);\n console.log(`[CRXJS] Retrying in ${timeout}ms...`);\n await new Promise((resolve) => setTimeout(resolve, timeout));\n }\n} while (!ready);\nchrome.runtime.reload();\n";
|
|
1413
1414
|
|
|
1414
|
-
var
|
|
1415
|
+
var loadingPageHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <title>Vite Dev Mode</title>\n <script src=\"%SCRIPT%\" type=\"module\"></script>\n </head>\n <body\n style=\"font-family: Arial, sans-serif; padding: 20px; text-align: center\"\n >\n <h1>Vite Dev Mode</h1>\n </body>\n</html>\n";
|
|
1415
1416
|
|
|
1416
1417
|
const { readFile } = promises;
|
|
1417
1418
|
const pluginManifest = () => {
|
|
@@ -1600,6 +1601,16 @@ const pluginManifest = () => {
|
|
|
1600
1601
|
});
|
|
1601
1602
|
manifest2.background.service_worker = refId2;
|
|
1602
1603
|
}
|
|
1604
|
+
if (manifest2.background && "scripts" in manifest2.background) {
|
|
1605
|
+
const file = manifest2.background.scripts[0];
|
|
1606
|
+
const id2 = join(config.root, file);
|
|
1607
|
+
const refId2 = this.emitFile({
|
|
1608
|
+
type: "chunk",
|
|
1609
|
+
id: id2,
|
|
1610
|
+
name: basename(file)
|
|
1611
|
+
});
|
|
1612
|
+
manifest2.background.scripts = [refId2];
|
|
1613
|
+
}
|
|
1603
1614
|
for (const file of htmlFiles(manifest2)) {
|
|
1604
1615
|
const id2 = join(config.root, file);
|
|
1605
1616
|
this.emitFile({
|
|
@@ -1629,6 +1640,11 @@ const pluginManifest = () => {
|
|
|
1629
1640
|
const name = this.getFileName(ref);
|
|
1630
1641
|
manifest2.background.service_worker = name;
|
|
1631
1642
|
}
|
|
1643
|
+
if (manifest2.background && "scripts" in manifest2.background) {
|
|
1644
|
+
const ref = manifest2.background.scripts[0];
|
|
1645
|
+
const name = this.getFileName(ref);
|
|
1646
|
+
manifest2.background.scripts = [name];
|
|
1647
|
+
}
|
|
1632
1648
|
manifest2.content_scripts = manifest2.content_scripts?.map(
|
|
1633
1649
|
({ js = [], ...rest }) => {
|
|
1634
1650
|
return {
|
|
@@ -1697,17 +1713,20 @@ Public dir: "${config.publicDir}"`
|
|
|
1697
1713
|
if (config.command === "serve" && files.html.length) {
|
|
1698
1714
|
const refId2 = this.emitFile({
|
|
1699
1715
|
type: "asset",
|
|
1700
|
-
name: "
|
|
1701
|
-
source:
|
|
1716
|
+
name: "loading-page.js",
|
|
1717
|
+
source: loadingPageScript.replace(
|
|
1718
|
+
"%PORT%",
|
|
1719
|
+
`${config.server.port ?? 0}`
|
|
1720
|
+
)
|
|
1702
1721
|
});
|
|
1703
|
-
const
|
|
1722
|
+
const loadingPageScriptName = this.getFileName(refId2);
|
|
1704
1723
|
files.html.map(
|
|
1705
1724
|
(f) => this.emitFile({
|
|
1706
1725
|
type: "asset",
|
|
1707
1726
|
fileName: f,
|
|
1708
|
-
source:
|
|
1727
|
+
source: loadingPageHtml.replace(
|
|
1709
1728
|
"%SCRIPT%",
|
|
1710
|
-
`/${
|
|
1729
|
+
`/${loadingPageScriptName}`
|
|
1711
1730
|
)
|
|
1712
1731
|
})
|
|
1713
1732
|
);
|