deno-embedder v2
The release of Deno v2.4 brings a lot of deno-embedder's features to Deno. 🎉 https://deno.com/blog/v2.4
The first two bullet points in the announcement are:
-
deno bundle - Importing text and bytes
These are two things deno-embedder (and its ESBuild plugin) were built to provide. I'm glad these are now built-in!
For simple use cases, where you just need a few files embedded into your package, you probably don't need deno-embedder. But, I think there's still a value-add to the API deno-embedder provides:
- A "directory" interface for accessing embedded files.
- Gives a single location to see all embeds.
- Nice type-safe access to embeds by name.
- option to list all embeds, or access them dynamically (ex: based on the path of a web request).
- Can lazily load embeds as they're needed, instead of at module initialization (i.e.: application startup) time. (You can do this w/ SADIs directly, but the syntax is noisy, so it's going to be handy to have a single place to handle all that for you.)
- Optional/automatic compression of embedded assets.
- Reduces file size.
- (depending on usage patterns) may reduce memory usage.
So I've been brainstorming about what I might want to accomplish in a major v2 release. Here's my list so far:
- Deprecate the ESBuild plugin and create a plugin to delegate to
deno bundle --platform=browser. - Continue to generate the
dir.ts, but update it to support different modes:- Simple mode: Just add async on-demand statically-analyzable dynamic imports (SADIs) to embedded files, but use the new text/bytes import mechanism.
- Compression mode: Generate compressed copies of files before embedding them. (Transparently decompressing them when they're read at runtime.)
It looks like though Deno 2.4 supports text/bytes imports, JSR.io does not:
Task check:publish deno publish --unstable-raw-imports --dry-run
[...]
error[unstable-raw-import]: raw imports have not been stabilized
--> /Users/codyc/code/deno-embedder/examples/with-embedder/browser/generated/dir.ts:4:22
|
4 | "app.js": ()=>import("./app.js",{with:{type:"bytes"}}),
| ^^^^^^^^^^ the specifier
|
= hint: for the time being, embed the data directly into a JavaScript file (ex. as encoded base64 text)
docs: https://github.com/denoland/deno/issues/29904
So I'm going to put v2 development on hold until that is fixed.