This commit is contained in:
Seth Trowbridge 2024-07-05 08:54:39 -04:00
parent 2f21977fca
commit 3aa0b3a7ff
5 changed files with 24 additions and 19 deletions

View File

@ -1,16 +1,19 @@
# 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.
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***.
### Manual Bundle API
```typescript
import Bundle from "./mod.ts";
Bundle(
// ESBuild configuration:
// directory to work from
"./some_folder",
// ESBuild configuration (entry points are relative to "directory"):
{entry:["./app.tsx"]},
// import map:
// import map (if omitted, will scan for a deno configuration within "directory" and use that)
{"imports": {
"react": "https://esm.sh/preact@10.22.0/compat",
"react/": "https://esm.sh/preact@10.22.0/compat/"

View File

@ -3,8 +3,11 @@ import { parse as JSONC } from "https://deno.land/x/jsonct@v0.1.0/mod.ts";
type JsonLike = { [key: string]: string | string[] | JsonLike; };
/** A `file://` url version of Deno.cwd() (contains trailing slash) */
export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString() + "/";
export default async function HuntConfig(directory=Root)
export const Root:string = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString() + "/";
export default async function HuntConfig(directory=Root):Promise<{
imports: JsonLike;
compilerOptions: JsonLike;
}>
{
let path:string, json:JsonLike|undefined;
console.log("searchig in directory", directory)

11
jsapi.test.tsx Normal file
View File

@ -0,0 +1,11 @@
import * as Test from "https://deno.land/std@0.224.0/assert/mod.ts";
import Bundle, {ESBuild} from "./mod.ts";
const path = await import.meta.resolve("./test/");
const {outputFiles} = await Bundle(path, {entryPoints:["./app.tsx"]});
Deno.test("check", ()=>{
Test.assert(outputFiles?.length == 1);
Test.assert(outputFiles[0].text.length > 1000);
})

View File

@ -1,12 +0,0 @@
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);
if(outputFiles)
{
for(const item of outputFiles)
{
console.log(item.text);
}
}

View File

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