misc cleanup

This commit is contained in:
Seth Trowbridge 2024-07-03 15:09:21 -04:00
parent b5aece91e1
commit 2f21977fca
6 changed files with 43 additions and 24 deletions

13
.vscode/launch.json vendored
View File

@ -1,13 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request":"attach",
"name":"Attach",
"type": "node"
}
]
}

View File

@ -1,11 +1,9 @@
# Bundle that .TSX in your Deno project for the browser.
# ESBuild Typescript Bunder
## Supports import maps and runs on Deno Deploy
Uses the WASM version of ESBuild for use on Deno Deploy and adds some plugins to allow for import maps. Unfortunately, `npm:*` and `jsr:*` specifiers are not supported currently.
You can 1) run the bundler yourself and collect the transpiled output, or 2) just point the included static file server to some local (or HTTP!) files to get up and running quickly.
### TypeScript API
### Manual Bundle API
```typescript
import Bundle from "./mod.ts";
Bundle(
@ -18,5 +16,30 @@ Bundle(
"react/": "https://esm.sh/preact@10.22.0/compat/"
}}
);
if(outputFiles){
for(const item of outputFiles){
// do something with the output...
console.log(item.text);
}
}
```
### Static bundle server
#### API
```typescript
import Serve from "./serve.tsx";
Serve({path:"./some_folder", html:"index.html", port:8080});
```
#### CLI
```
deno run -A <hosted-location>/serve.tsx --path=./some_folder --html=index.html --port=8080
```
Accepts three optional settings:
- `path` A directory to serve content from. Defaults to the current working directory.
- `html` A path to an html file or actual html string to *always use* when the server would serve up a non-file route. If `html` is a path, it is assumed to be relative to `path`. If not specified, routes that don't match files will 404.
- `port` Port number (default is 8000).
When requests to typescript files are made to the server, it will treat that file as an entrypoint and return the corresponding plain javascript bundle.

View File

@ -1,9 +1,12 @@
import Bundle, { type ImportMap} from "./mod.ts";
import Bundle from "./mod.ts";
import Config from "./test/deno.json" with {type:"json"};
const path = import.meta.resolve("./test/");
const {outputFiles} = await Bundle(path, {entryPoints:["./app.tsx"]}, Config);
for(const item of outputFiles)
if(outputFiles)
{
console.log(item.text);
for(const item of outputFiles)
{
console.log(item.text);
}
}

View File

@ -8,7 +8,7 @@ if(Deno.mainModule == import.meta.url)
serve(parseArgs(Deno.args) as ServeArgs);
}
type ServeArgs = {path?:string, html?:string, port?:string|number};
export type ServeArgs = {path?:string, html?:string, port?:string|number};
async function serve(settings:ServeArgs):Promise<void>
{
// etag hash

View File

@ -1,6 +1,10 @@
{
"imports": {
"react": "https://esm.sh/preact@10.22.0/compat",
"react/": "https://esm.sh/preact@10.22.0/compat/"
"react": "npm:preact@10.22.0/compat",
"react/": "npm:preact@10.22.0/compat/"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
}
}

2
test/leaf.ts Normal file
View File

@ -0,0 +1,2 @@
const message:string = "leaf default export!"
export default ()=>console.log(message);