CodyC
DDeno
β’Created by ππΈβπΎπΌπ π»ππππ½πΈβπΌππ΅πΈ on 6/17/2024 in #help
Trouble with serving HTMl on localhost
I'm working on a little project that does SSR myself. Would love to hear about your framework.
Relatedly (shameless plug) I developed deno-embedder (https://jsr.io/@nfnitloop/deno-embedder) to make it easy to embed any static files necessary for SSR into the Deno binary so they all get bundled with
deno install
or deno compile
. Might be useful for you?10 replies
Deno JSR API package + CLI entrypoint "best-practices"
I have Opinions but, of course, everything depends on your use case(s).
1. Have the mod.ts entrypoint exports both the JS API and the CLI (under import.meta.main)This is my preferred path, for ease-of-use for users. They gete a short package path, and
deno install
will likely install with a name that makes sense for your package.
I assume by "under import.meta.main" you mean that you have a call to main()
in your mod.ts that's guarded by an if (import.meta.main) {
. π
You may want to export your main()
function too, so folks can execute it from a script, instead of having to execute it as a standalone process. Depends on your use case. (ex: that might be less useful if your CLI is very interactive.) If you're also exposing an API, that may be a better way for them to use it.
2. Have multiple entrypoints, but the imports won't be "pretty" (eg. jsr:@scope/myThing/cli.ts)JSR exports can be prettier than that. You can have an export "cli" which maps to "cli.ts" internally. The downside here is that, I think if you
deno install
that, you're going to get a script called cli
which isn't very user-friendly.
1 & 2 don't have to be exclusive. You can do both. Have a default (./
) entrypoint which can act as main and exposes the API, and a separate /api
export which only gives the API for those that want a smaller dependency graph.
3. Separate the CLI into a separate packageYeah, this seems like overkill until your project gets quite large. Managing two(+) separate packages that are tightly coupled is a headache.
3 replies
Plain javascript in .js files in vscode
You may already know, but to tell
deno
to allow (and autocomplete) DOM types, you'll need to add "dom" to compilerOptions.lib
in deno.json[c].
See: https://docs.deno.com/runtime/manual/advanced/typescript/configuration#using-the-lib-property
Unfortunately, these compiler options seem to be project-wide, even if you specify them with triple-slash directives in individual files.
The only way I've seen to have separate rules for separate files is to make them separate deno projects.3 replies
Problem with www.
I see they both resolve to the same IP addresses, so it looks like DNS is correct. β
I haven't used Deno Deploy, but services usually have a configuration that lists which domain name(s) that they should respond to with your content. You probably need to find that in Deno Deploy settings and add www. to the list.
2 replies
How to open a file as blob?
see this conversation for more details: https://github.com/denoland/deno/discussions/10539
20 replies
How to open a file as blob?
https://developer.mozilla.org/en-US/docs/Web/API/Blob
Blobs can represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.
20 replies
How to open a file as blob?
The Blob API supports asynchronously reading slices of the underlying file with a very nice API:
* any Blob can synchronously get a blob.slice() which itself is a Blob.
* Only when reading the bytes is async required, to wait for the bytes from the underlying store.
20 replies
How to open a file as blob?
Yep. I should've stated that I was looking for a solution that didn't require reading the entire file into memory, because that's trivially easy, and I'm looking to use the Blob API so that I don't have to hold the whole thing in memory. π
20 replies
Help debugging command that doesn't exit.
There's an undocumented stop() method that you have to call to avoid this problem. π€¦
https://deno.land/x/esbuild@v0.17.12/mod.js?s=stop
This doesn't seem to be documented in the official API docs:
https://esbuild.github.io/api/
4 replies