feat: add support for preact devtools in dev mode (#639)

Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
Marvin Hagemeister
2022-08-23 13:29:12 +00:00
committed by GitHub
co-authored by Luca Casonato
parent d798db2a5f
commit 7e0278bbb3
3 changed files with 26 additions and 4 deletions
+2
View File
@@ -0,0 +1,2 @@
import "preact/debug";
export { revive } from "./main.ts";
+18 -3
View File
@@ -1,3 +1,4 @@
import { BuildOptions } from "https://deno.land/x/esbuild@v0.14.51/mod.js";
import { BUILD_ID } from "./constants.ts";
import { denoPlugin, esbuild, toFileUrl } from "./deps.ts";
import { Island, Plugin } from "./types.ts";
@@ -25,16 +26,25 @@ export class Bundler {
#islands: Island[];
#plugins: Plugin[];
#cache: Map<string, Uint8Array> | Promise<void> | undefined = undefined;
#dev: boolean;
constructor(islands: Island[], plugins: Plugin[], importMapURL: URL) {
constructor(
islands: Island[],
plugins: Plugin[],
importMapURL: URL,
dev: boolean,
) {
this.#islands = islands;
this.#plugins = plugins;
this.#importMapURL = importMapURL;
this.#dev = dev;
}
async bundle() {
const entryPoints: Record<string, string> = {
"main": new URL("../../src/runtime/main.ts", import.meta.url).href,
main: this.#dev
? new URL("../../src/runtime/main_dev.ts", import.meta.url).href
: new URL("../../src/runtime/main.ts", import.meta.url).href,
};
for (const island of this.#islands) {
@@ -49,13 +59,18 @@ export class Bundler {
const absWorkingDir = Deno.cwd();
await ensureEsbuildInitialized();
// In dev-mode we skip identifier minification to be able to show proper
// component names in Preact DevTools instead of single characters.
const minifyOptions: Partial<BuildOptions> = this.#dev
? { minifyIdentifiers: false, minifySyntax: true, minifyWhitespace: true }
: { minify: true };
const bundle = await esbuild.build({
bundle: true,
define: { __FRSH_BUILD_ID: `"${BUILD_ID}"` },
entryPoints,
format: "esm",
metafile: true,
minify: true,
...minifyOptions,
outdir: ".",
// This is requried to ensure the format of the outputFiles path is the same
// between windows and linux
+6 -1
View File
@@ -85,8 +85,13 @@ export class ServerContext {
this.#notFound = notFound;
this.#error = error;
this.#plugins = plugins;
this.#bundler = new Bundler(this.#islands, this.#plugins, importMapURL);
this.#dev = typeof Deno.env.get("DENO_DEPLOYMENT_ID") !== "string"; // Env var is only set in prod (on Deploy).
this.#bundler = new Bundler(
this.#islands,
this.#plugins,
importMapURL,
this.#dev,
);
}
/**