@crxjs/vite-plugin 2.0.0-beta.21 → 2.0.0-beta.23

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.
Files changed (2) hide show
  1. package/dist/index.mjs +6 -5
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ import * as lexer from 'es-module-lexer';
11
11
  import { readFile as readFile$1 } from 'fs/promises';
12
12
  import MagicString from 'magic-string';
13
13
  import convertSourceMap from 'convert-source-map';
14
- import { createLogger } from 'vite';
14
+ import { createLogger, version } from 'vite';
15
15
  import { readFileSync, existsSync, promises } from 'fs';
16
16
  import { createRequire } from 'module';
17
17
  import fg from 'fast-glob';
@@ -1238,7 +1238,6 @@ const pluginHMR = () => {
1238
1238
  if (relFiles.has(background) || modules.some(isImporter(join(server.config.root, background)))) {
1239
1239
  debug$1("sending runtime reload");
1240
1240
  server.ws.send(crxRuntimeReload);
1241
- return [];
1242
1241
  }
1243
1242
  }
1244
1243
  for (const [key, script] of contentScripts)
@@ -1410,7 +1409,7 @@ const pluginHtmlInlineScripts = () => {
1410
1409
  };
1411
1410
  };
1412
1411
 
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";
1412
+ 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);\nlocation.reload();\n";
1414
1413
 
1415
1414
  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";
1416
1415
 
@@ -1880,9 +1879,11 @@ const pluginWebAccessibleResources = () => {
1880
1879
  dynamicScriptMatches.add("https://*/*");
1881
1880
  }
1882
1881
  if (contentScripts.size > 0) {
1882
+ const viteMajorVersion = parseInt(version.split(".")[0]);
1883
+ const manifestPath = viteMajorVersion > 4 ? ".vite/manifest.json" : "manifest.json";
1883
1884
  const viteManifest = parseJsonAsset(
1884
1885
  bundle,
1885
- "manifest.json"
1886
+ manifestPath
1886
1887
  );
1887
1888
  const viteFiles = /* @__PURE__ */ new Map();
1888
1889
  for (const [, file] of Object.entries(viteManifest))
@@ -1910,7 +1911,7 @@ const pluginWebAccessibleResources = () => {
1910
1911
  { chunks: bundleChunks, files: viteFiles, config }
1911
1912
  );
1912
1913
  contentScripts.get(key).css = [...css];
1913
- if (type === "loader")
1914
+ if (type === "loader" || isDynamicScript)
1914
1915
  imports.add(fileName);
1915
1916
  const resource = {
1916
1917
  matches: isDynamicScript ? [...dynamicScriptMatches] : matches,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crxjs/vite-plugin",
3
- "version": "2.0.0-beta.21",
3
+ "version": "2.0.0-beta.23",
4
4
  "description": "Build Chrome Extensions with this Vite plugin.",
5
5
  "keywords": [
6
6
  "rollup-plugin",