fix(js): only register devhook when running with devserver

Fixes: https://github.com/ziex-dev/ziex/issues/158
This commit is contained in:
Nurul Huda (Apon) 2026-06-26 20:51:59 +06:00
parent 381b1cf0a4
commit f4815c8bb1
No known key found for this signature in database
GPG Key ID: 5D3F1DE2855A2F79
2 changed files with 22 additions and 4 deletions

View File

@ -31,6 +31,9 @@ async function main() {
entrypoints: [join(pkgDir, "src/index.ts"), join(pkgDir, "src/react/index.ts"), join(pkgDir, "src/wasm/index.ts"), join(pkgDir, "src/cloudflare/index.ts"), join(pkgDir, "src/aws-lambda/index.ts"), join(pkgDir, "src/vercel/index.ts")],
outdir: pkgDistDir,
// minify: true,
define: {
__DEV__: "true",
}
});
// Build standalone WASM init script (auto-initializes, for direct <script> usage)
@ -38,8 +41,23 @@ async function main() {
await Bun.build({
entrypoints: [join(pkgDir, "src/wasm/init.ts")],
outdir: join(pkgDistDir, "wasm"),
minify: false,
minify: true,
naming: "[name].js",
define: {
__DEV__: "false",
}
});
// Build standalone WASM init script (auto-initializes, for direct <script> usage)
console.log(`\x1b[33m📦 ${pkgName} - Building standalone dev wasm/init.dev.js...\x1b[0m`);
await Bun.build({
entrypoints: [join(pkgDir, "src/wasm/init.ts")],
outdir: join(pkgDistDir, "wasm"),
minify: false,
naming: "[name].dev.js",
define: {
__DEV__: "true",
}
});
// Generate TypeScript declaration files

View File

@ -761,15 +761,15 @@ export async function init(options: InitOptions = {}): Promise<{ source: WebAsse
},
};
// TODO: dev only and prebundle a dev and prod version before publishing
// if (import.meta.env.DEV)
registerDevReinit(normalizedOptions);
if (typeof __DEV__ !== "undefined" && __DEV__) registerDevReinit(normalizedOptions);
return { source, bridge };
}
// Global type declarations
declare global {
const __DEV__: boolean;
interface HTMLElement {
__zx_ref?: number;
}