preact
This commit is contained in:
parent
6acf267d48
commit
b7614eb3f8
4794 changed files with 1280808 additions and 1546 deletions
50
frontend/node_modules/@preact/preset-vite/dist/esm/devtools.mjs
generated
vendored
Normal file
50
frontend/node_modules/@preact/preset-vite/dist/esm/devtools.mjs
generated
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { normalizePath } from "vite";
|
||||
import path from "path";
|
||||
import debug from "debug";
|
||||
import pc from "picocolors";
|
||||
import { parseId } from "./utils.mjs";
|
||||
export function preactDevtoolsPlugin({ devtoolsInProd, devToolsEnabled, shouldTransform, }) {
|
||||
const log = debug("vite:preact-devtools");
|
||||
let entry = "";
|
||||
let config;
|
||||
let found = false;
|
||||
const plugin = {
|
||||
name: "preact:devtools",
|
||||
// Ensure that we resolve before everything else
|
||||
enforce: "pre",
|
||||
config() {
|
||||
return {
|
||||
optimizeDeps: {
|
||||
include: ["preact/debug", "preact/devtools"],
|
||||
},
|
||||
};
|
||||
},
|
||||
configResolved(resolvedConfig) {
|
||||
config = resolvedConfig;
|
||||
devToolsEnabled =
|
||||
devToolsEnabled !== null && devToolsEnabled !== void 0 ? devToolsEnabled : (!config.isProduction || devtoolsInProd);
|
||||
},
|
||||
resolveId(url, importer = "") {
|
||||
const { id } = parseId(url);
|
||||
// Get the main entry file to inject into
|
||||
if (!found && /\.html$/.test(importer) && shouldTransform(id)) {
|
||||
found = true;
|
||||
entry = normalizePath(path.join(config.root, id));
|
||||
// TODO: Vite types require explicit return
|
||||
// undefined here. They're lacking the "void" type
|
||||
// in their declarations
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
transform(code, url) {
|
||||
const { id } = parseId(url);
|
||||
if (entry === id && (!config.isProduction || devToolsEnabled)) {
|
||||
const source = config.isProduction ? "preact/devtools" : "preact/debug";
|
||||
code = `import "${source}";\n${code}`;
|
||||
log(`[inject] ${pc.cyan(source)} -> ${pc.dim(id)}`);
|
||||
return code;
|
||||
}
|
||||
},
|
||||
};
|
||||
return plugin;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue