feat: add support for preact devtools in dev mode (#639)
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
co-authored by
Luca Casonato
parent
d798db2a5f
commit
7e0278bbb3
@@ -0,0 +1,2 @@
|
|||||||
|
import "preact/debug";
|
||||||
|
export { revive } from "./main.ts";
|
||||||
+18
-3
@@ -1,3 +1,4 @@
|
|||||||
|
import { BuildOptions } from "https://deno.land/x/esbuild@v0.14.51/mod.js";
|
||||||
import { BUILD_ID } from "./constants.ts";
|
import { BUILD_ID } from "./constants.ts";
|
||||||
import { denoPlugin, esbuild, toFileUrl } from "./deps.ts";
|
import { denoPlugin, esbuild, toFileUrl } from "./deps.ts";
|
||||||
import { Island, Plugin } from "./types.ts";
|
import { Island, Plugin } from "./types.ts";
|
||||||
@@ -25,16 +26,25 @@ export class Bundler {
|
|||||||
#islands: Island[];
|
#islands: Island[];
|
||||||
#plugins: Plugin[];
|
#plugins: Plugin[];
|
||||||
#cache: Map<string, Uint8Array> | Promise<void> | undefined = undefined;
|
#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.#islands = islands;
|
||||||
this.#plugins = plugins;
|
this.#plugins = plugins;
|
||||||
this.#importMapURL = importMapURL;
|
this.#importMapURL = importMapURL;
|
||||||
|
this.#dev = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
async bundle() {
|
async bundle() {
|
||||||
const entryPoints: Record<string, string> = {
|
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) {
|
for (const island of this.#islands) {
|
||||||
@@ -49,13 +59,18 @@ export class Bundler {
|
|||||||
|
|
||||||
const absWorkingDir = Deno.cwd();
|
const absWorkingDir = Deno.cwd();
|
||||||
await ensureEsbuildInitialized();
|
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({
|
const bundle = await esbuild.build({
|
||||||
bundle: true,
|
bundle: true,
|
||||||
define: { __FRSH_BUILD_ID: `"${BUILD_ID}"` },
|
define: { __FRSH_BUILD_ID: `"${BUILD_ID}"` },
|
||||||
entryPoints,
|
entryPoints,
|
||||||
format: "esm",
|
format: "esm",
|
||||||
metafile: true,
|
metafile: true,
|
||||||
minify: true,
|
...minifyOptions,
|
||||||
outdir: ".",
|
outdir: ".",
|
||||||
// This is requried to ensure the format of the outputFiles path is the same
|
// This is requried to ensure the format of the outputFiles path is the same
|
||||||
// between windows and linux
|
// between windows and linux
|
||||||
|
|||||||
@@ -85,8 +85,13 @@ export class ServerContext {
|
|||||||
this.#notFound = notFound;
|
this.#notFound = notFound;
|
||||||
this.#error = error;
|
this.#error = error;
|
||||||
this.#plugins = plugins;
|
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.#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,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user