wxt 0.7.3 → 0.7.4
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/cli.cjs +110 -53
- package/dist/index.cjs +109 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +109 -52
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -949,62 +949,119 @@ function resolvePerBrowserOption(option, browser) {
|
|
|
949
949
|
// src/core/vite-plugins/devHtmlPrerender.ts
|
|
950
950
|
import { parseHTML } from "linkedom";
|
|
951
951
|
import { dirname as dirname2, isAbsolute, relative as relative2, resolve as resolve3 } from "path";
|
|
952
|
+
var reactRefreshPreamble = "";
|
|
952
953
|
function devHtmlPrerender(config) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
954
|
+
const htmlReloadId = "@wxt/reload-html";
|
|
955
|
+
const resolvedHtmlReloadId = resolve3(
|
|
956
|
+
config.root,
|
|
957
|
+
"node_modules/wxt/dist/virtual-modules/reload-html.js"
|
|
958
|
+
);
|
|
959
|
+
const virtualReactRefreshId = "@wxt/virtual-react-refresh";
|
|
960
|
+
const resolvedVirtualReactRefreshId = "\0" + virtualReactRefreshId;
|
|
961
|
+
return [
|
|
962
|
+
{
|
|
963
|
+
apply: "build",
|
|
964
|
+
name: "wxt:dev-html-prerender",
|
|
965
|
+
config() {
|
|
966
|
+
return {
|
|
967
|
+
resolve: {
|
|
968
|
+
alias: {
|
|
969
|
+
[htmlReloadId]: resolvedHtmlReloadId
|
|
970
|
+
}
|
|
964
971
|
}
|
|
972
|
+
};
|
|
973
|
+
},
|
|
974
|
+
// Convert scripts like src="./main.tsx" -> src="http://localhost:3000/entrypoints/popup/main.tsx"
|
|
975
|
+
// before the paths are replaced with their bundled path
|
|
976
|
+
transform(code, id) {
|
|
977
|
+
const server = config.server;
|
|
978
|
+
if (config.command !== "serve" || server == null || !id.endsWith(".html"))
|
|
979
|
+
return;
|
|
980
|
+
const { document } = parseHTML(code);
|
|
981
|
+
const pointToDevServer = (querySelector, attr) => {
|
|
982
|
+
document.querySelectorAll(querySelector).forEach((element) => {
|
|
983
|
+
const src = element.getAttribute(attr);
|
|
984
|
+
if (!src)
|
|
985
|
+
return;
|
|
986
|
+
if (isAbsolute(src)) {
|
|
987
|
+
element.setAttribute(attr, server.origin + src);
|
|
988
|
+
} else if (src.startsWith(".")) {
|
|
989
|
+
const abs = resolve3(dirname2(id), src);
|
|
990
|
+
const pathname = relative2(config.root, abs);
|
|
991
|
+
element.setAttribute(attr, `${server.origin}/${pathname}`);
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
};
|
|
995
|
+
pointToDevServer("script[type=module]", "src");
|
|
996
|
+
pointToDevServer("link[rel=stylesheet]", "href");
|
|
997
|
+
const reloader = document.createElement("script");
|
|
998
|
+
reloader.src = htmlReloadId;
|
|
999
|
+
reloader.type = "module";
|
|
1000
|
+
document.head.appendChild(reloader);
|
|
1001
|
+
const newHtml = document.toString();
|
|
1002
|
+
config.logger.debug("transform " + id);
|
|
1003
|
+
config.logger.debug("Old HTML:\n" + code);
|
|
1004
|
+
config.logger.debug("New HTML:\n" + newHtml);
|
|
1005
|
+
return newHtml;
|
|
1006
|
+
},
|
|
1007
|
+
// Pass the HTML through the dev server to add dev-mode specific code
|
|
1008
|
+
async transformIndexHtml(html, ctx) {
|
|
1009
|
+
const server = config.server;
|
|
1010
|
+
if (config.command !== "serve" || server == null)
|
|
1011
|
+
return;
|
|
1012
|
+
const originalUrl = `${server.origin}${ctx.path}`;
|
|
1013
|
+
const name = getEntrypointName(config.entrypointsDir, ctx.filename);
|
|
1014
|
+
const url2 = `${server.origin}/${name}.html`;
|
|
1015
|
+
const serverHtml = await server.transformIndexHtml(
|
|
1016
|
+
url2,
|
|
1017
|
+
html,
|
|
1018
|
+
originalUrl
|
|
1019
|
+
);
|
|
1020
|
+
const { document } = parseHTML(serverHtml);
|
|
1021
|
+
const reactRefreshScript = Array.from(
|
|
1022
|
+
document.querySelectorAll("script[type=module]")
|
|
1023
|
+
).find((script) => script.innerHTML.includes("@react-refresh"));
|
|
1024
|
+
if (reactRefreshScript) {
|
|
1025
|
+
reactRefreshPreamble = reactRefreshScript.innerHTML;
|
|
1026
|
+
const virtualScript = document.createElement("script");
|
|
1027
|
+
virtualScript.type = "module";
|
|
1028
|
+
virtualScript.src = `${server.origin}/${virtualReactRefreshId}`;
|
|
1029
|
+
reactRefreshScript.replaceWith(virtualScript);
|
|
965
1030
|
}
|
|
966
|
-
|
|
1031
|
+
const viteClientScript = document.querySelector(
|
|
1032
|
+
"script[src='/@vite/client']"
|
|
1033
|
+
);
|
|
1034
|
+
if (viteClientScript) {
|
|
1035
|
+
viteClientScript.src = `${server.origin}${viteClientScript.src}`;
|
|
1036
|
+
}
|
|
1037
|
+
const newHtml = document.toString();
|
|
1038
|
+
config.logger.debug("transformIndexHtml " + ctx.filename);
|
|
1039
|
+
config.logger.debug("Old HTML:\n" + html);
|
|
1040
|
+
config.logger.debug("New HTML:\n" + newHtml);
|
|
1041
|
+
return newHtml;
|
|
1042
|
+
}
|
|
967
1043
|
},
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
)
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
element.setAttribute(attr, server.origin + src);
|
|
988
|
-
} else if (src.startsWith(".")) {
|
|
989
|
-
const abs = resolve3(dirname2(id), src);
|
|
990
|
-
const pathname = relative2(config.root, abs);
|
|
991
|
-
element.setAttribute(attr, `${server.origin}/${pathname}`);
|
|
992
|
-
}
|
|
993
|
-
});
|
|
994
|
-
};
|
|
995
|
-
pointToDevServer("script[type=module]", "src");
|
|
996
|
-
pointToDevServer("link[rel=stylesheet]", "href");
|
|
997
|
-
const reloader = document.createElement("script");
|
|
998
|
-
reloader.src = "@wxt/reload-html";
|
|
999
|
-
reloader.type = "module";
|
|
1000
|
-
document.head.appendChild(reloader);
|
|
1001
|
-
const newHtml = document.toString();
|
|
1002
|
-
config.logger.debug("Transformed " + id);
|
|
1003
|
-
config.logger.debug("Old HTML:\n" + html);
|
|
1004
|
-
config.logger.debug("New HTML:\n" + newHtml);
|
|
1005
|
-
return newHtml;
|
|
1044
|
+
{
|
|
1045
|
+
name: "wxt:virtualize-react-refresh",
|
|
1046
|
+
apply: "serve",
|
|
1047
|
+
resolveId(id) {
|
|
1048
|
+
if (id === `/${virtualReactRefreshId}`) {
|
|
1049
|
+
return resolvedVirtualReactRefreshId;
|
|
1050
|
+
}
|
|
1051
|
+
if (id.startsWith("/chunks/")) {
|
|
1052
|
+
return "\0noop";
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
load(id) {
|
|
1056
|
+
if (id === resolvedVirtualReactRefreshId) {
|
|
1057
|
+
return reactRefreshPreamble;
|
|
1058
|
+
}
|
|
1059
|
+
if (id === "\0noop") {
|
|
1060
|
+
return "";
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1006
1063
|
}
|
|
1007
|
-
|
|
1064
|
+
];
|
|
1008
1065
|
}
|
|
1009
1066
|
|
|
1010
1067
|
// src/core/vite-plugins/devServerGlobals.ts
|
|
@@ -4496,7 +4553,7 @@ async function clean(root = process.cwd()) {
|
|
|
4496
4553
|
}
|
|
4497
4554
|
|
|
4498
4555
|
// package.json
|
|
4499
|
-
var version2 = "0.7.
|
|
4556
|
+
var version2 = "0.7.4";
|
|
4500
4557
|
|
|
4501
4558
|
// src/core/utils/defineConfig.ts
|
|
4502
4559
|
function defineConfig(config) {
|