esbuild-wasm-bundler/README.md

49 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2024-07-03 15:09:21 -04:00
# ESBuild Typescript Bunder
2024-06-12 17:05:41 -04:00
## Supports import maps and runs on Deno Deploy
2024-07-05 08:54:39 -04:00
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***.
2024-06-12 17:05:41 -04:00
2024-07-03 15:09:21 -04:00
### Manual Bundle API
2024-06-12 17:05:41 -04:00
```typescript
import Bundle from "./mod.ts";
Bundle(
2024-07-05 08:54:39 -04:00
// directory to work from
"./some_folder",
// ESBuild configuration (entry points are relative to "directory"):
2024-06-12 17:05:41 -04:00
{entry:["./app.tsx"]},
2024-07-05 08:54:39 -04:00
// import map (if omitted, will scan for a deno configuration within "directory" and use that)
2024-06-12 17:05:41 -04:00
{"imports": {
"react": "https://esm.sh/preact@10.22.0/compat",
"react/": "https://esm.sh/preact@10.22.0/compat/"
}}
);
2024-07-03 15:09:21 -04:00
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
2024-06-12 17:05:41 -04:00
```
2024-07-03 15:09:21 -04:00
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).
2024-06-12 17:05:41 -04:00
2024-07-03 15:09:21 -04:00
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.