diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index eb9ace7..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -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" - } - ] -} \ No newline at end of file diff --git a/README.md b/README.md index f8588ee..286dfd7 100644 --- a/README.md +++ b/README.md @@ -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 /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. diff --git a/jsapi.tsx b/jsapi.tsx index 4001c3c..c534a27 100644 --- a/jsapi.tsx +++ b/jsapi.tsx @@ -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); + } } diff --git a/serve.tsx b/serve.tsx index 3e819f0..283ec83 100644 --- a/serve.tsx +++ b/serve.tsx @@ -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 { // etag hash diff --git a/test/deno.json b/test/deno.json index a306003..56ee7b3 100644 --- a/test/deno.json +++ b/test/deno.json @@ -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" } } \ No newline at end of file diff --git a/test/leaf.ts b/test/leaf.ts new file mode 100644 index 0000000..9ff7736 --- /dev/null +++ b/test/leaf.ts @@ -0,0 +1,2 @@ +const message:string = "leaf default export!" +export default ()=>console.log(message);