Web Bundle and Isolated Web App experiments
bun install
or
npm install
Programmatically create node_modules
folder and add wbn-sign-webcrypto
to the folder from the GitHub repository
deno run -A deno_install.js
Dynamically fetch dependencies without creating a node_modules
folder and create the .swbn
file and IWA.
deno run -A --unstable-byonm --import-map=deno.json index.js
Entry point is assets
directory; contains manifest.webmanifest
, index.html
, script.js
and any other scripts or resources to be bundled.
This only has to be done once.
node --experimental-default-type=module generateWebCryptoKeys.js
Write signed.swbn
to current directory
Node.js
node --experimental-default-type=module index.js
Bun
bun run index.js
Deno
deno run --unstable-byonm -A index.js
Navigate to chrome://web-app-internals/
, click Select file...
and select signed.swbn
.
try {
console.log(
await Bun.build({
entrypoints: ["./src/index.ts"],
outdir: ".",
sourcemap: "external",
splitting: false,
target: "bun" // or "node"
format: "esm",
// minify: true,
external: ["mime", "base32-encode", "wbn-sign-webcrypto", "wbn"],
naming: {
entry: "[dir]/wbn-bundle.[ext]",
},
}),
);
} catch (e) {
console.log(e);
}
// import bundleIsolatedWebApp from "./wbn-bundle.js";
import * as esbuild from "esbuild";
// Deno-specific workaround for dynamic imports.
const dynamicImport = "./wbn-bundle.js";
await esbuild.build({
entryPoints: ["src/index.ts"],
platform: "node",
outfile: dynamicImport,
format: "esm",
packages: "external",
legalComments: "inline",
sourcemap: true,
bundle: true,
keepNames: true,
allowOverwrite: true,
});
// https://github.com/denoland/deno/issues/20945
// "" + "/path" and "/path" + "": Deno-specific workaround to avoid module not found error
const { default: bundleIsolatedWebApp } = await import(dynamicImport);
Note, this is possible using Deno without node_modules
in the current directory, using the import map in deno.json
. deno
creates a node_modules
folder, fetches and populate with the compile dependencies @types/node
, undici-types
, then compiles and outputs the self-contained executable, 96.8 MB (after strip deno
).
deno compile -A --output deno_webbundle ./index.js
When node_modules
populated with dependencies, creates a 89.1 MB (after strip bun
) standalone binary.
bun build ./index.js --compile --outfile=bun_webbundle
- This should work in the browser.
- Install and run using
deno
without needing to run import the dynamically created bundlewbn-bundle.js
twice; the first run throwing module not found error. For now generate and import the bundle twice; the first dynamic import indeno_install.js
, catching the error, to avoid the error for first run being thrown inrollup.wbn.js
which generates thesigned.swbn
file. Completed (see this commit). - Install
wbn-sign-webcrypto
dependency from GitHub repository usingdeno
. Completed. - Substitute Web Cryptography API for
node:crypto
. Completed.
Do What the Fuck You Want to Public License WTFPLv2