aboutsummaryrefslogtreecommitdiff
path: root/docs/runtime/loaders.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/runtime/loaders.md')
-rw-r--r--docs/runtime/loaders.md81
1 files changed, 80 insertions, 1 deletions
diff --git a/docs/runtime/loaders.md b/docs/runtime/loaders.md
index c7977534c..78f1b44c0 100644
--- a/docs/runtime/loaders.md
+++ b/docs/runtime/loaders.md
@@ -1,3 +1,82 @@
+## TypeScript
+
+Bun natively supports TypeScript out of the box. All files are transpiled on the fly by Bun's fast native transpiler before being executed. Similar to other build tools, Bun does not perform typechecking; it simply removes type annotations from the file.
+
+```bash
+$ bun index.js
+$ bun index.jsx
+$ bun index.ts
+$ bun index.tsx
+```
+
+Some aspects of Bun's runtime behavior are affected by the contents of your `tsconfig.json` file. Refer to [Runtime > TypeScript](/docs/runtime/typescript) page for details.
+
+## JSX
+
+Bun supports `.jsx` and `.tsx` files out of the box. Bun's internal transpiler converts JSX syntax into vanilla JavaScript before execution.
+
+```tsx#react.tsx
+function Component(props: {message: string}) {
+ return (
+ <body>
+ <h1 style={{color: 'red'}}>{props.message}</h1>
+ </body>
+ );
+}
+
+console.log(<Component message="Hello world!" />);
+```
+
+Bun implements special logging for JSX to make debugging easier.
+
+```bash
+$ bun run react.tsx
+<Component message="Hello world!" />
+```
+
+## JSON and TOML
+
+JSON and TOML files can be directly imported from a source file. The contents will be loaded and returned as a JavaScript object.
+
+```ts
+import pkg from "./package.json";
+import data from "./data.toml";
+```
+
+## WASM
+
+As of v0.5.2, experimental support exists for WASI, the [WebAssembly System Interface](https://github.com/WebAssembly/WASI). To run a `.wasm` binary with Bun:
+
+```bash
+$ bun ./my-wasm-app.wasm
+# if the filename doesn't end with ".wasm"
+$ bun run ./my-wasm-app.whatever
+```
+
+{% callout %}
+
+**Note** — WASI support is based on [wasi-js](https://github.com/sagemathinc/cowasm/tree/main/packages/wasi-js). Currently, it only supports WASI binaries that use the `wasi_snapshot_preview1` or `wasi_unstable` APIs. Bun's implementation is not fully optimized for performance; this will become more of a priority as WASM grows in popularity.
+{% /callout %}
+
+## Unknown file types
+
+By default, when Bun encounters an import with an unsupported file extension, it returns an absolute path to the location on disk.
+
+```ts
+import file from "./movie.mp4";
+
+file;
+// /path/to/movie.mp4
+```
+
+Note: This behavior only applies when executing a file with `bun run`! When using Bun's bundler, the behavior may be different depending on your bundler configuration.
+
+## Custom loaders
+
+Support for additional file types can be implemented with plugins. Refer to [Runtime > Plugins](/docs/runtime/plugins) for full documentation.
+
+<!--
+
A loader determines how to map imports &amp; file extensions to transforms and output.
Currently, Bun implements the following loaders:
@@ -25,4 +104,4 @@ You can configure which loaders map to which extensions by passing `--loaders` t
$ bun --loader=.js:js
```
-This will disable JSX transforms for `.js` files.
+This will disable JSX transforms for `.js` files. -->
fix(node:http): match Node `http.request()` GET/HEAD w/ body (#2262)Gravatar Derrick Farris 2-2/+31 2023-03-01Add a test for https request in node:httpGravatar Jarred Sumner 2-17/+28 2023-03-01fix(node:http/https): fix passing `URL` objs to `http.request`(#2253) (#2258)Gravatar Derrick Farris 2-43/+63 2023-03-01Revert "Update clap (#2238)"Gravatar Jarred Sumner 16-290/+1840 2023-03-01Revert "Add `-D`, `--dev` flags for bun install (#2240)"Gravatar Jarred Sumner 1-9/+9 2023-03-01Use GitHub action ID instead of SHA for test workflowGravatar Ashcon Partovi 1-1/+1 2023-03-01avoids segfault after aborted onReject in Bun.serve streams (#2256)Gravatar Ciro Spaciari 1-7/+8 2023-03-01Run tests in CI for bun-linux-aarch64Gravatar Ashcon Partovi 2-1/+30 2023-03-01Revert spawnSync changeGravatar Jarred Sumner 1-1/+2 2023-03-01Update bindings.zigGravatar Jarred Sumner 1-1/+3 2023-03-01fix deinit behavior when connection is aborted using ResponseStream and abort...Gravatar Ciro Spaciari 3-34/+174 2023-03-01fix Bun.file.arrayBuffer() segmentation fault on empty file #2248 (#2249)Gravatar Ciro Spaciari 3-7/+23 2023-03-01Fix async in sqliteGravatar Colin McDonnell 1-2/+2 2023-02-28Forces a specific libdir for c-ares (#2241)Gravatar Justin Whear 1-1/+5 2023-02-28Make Bun.gc(true) more aggressiveGravatar Jarred Sumner 1-0/+3 2023-02-28Expose JSC::Options via `BUN_JSC_` prefixGravatar Jarred Sumner 6-8/+47 2023-02-28fixupGravatar Jarred Sumner 1-1/+1 2023-02-28Fix typecheckGravatar Colin McDonnell 2-1/+4 2023-02-28Fix incorrect Bun version in docs (#2236)Gravatar Derrick Farris 1-1/+1 2023-02-28just some comments fix (#2237)Gravatar Ciro Spaciari 1-4/+2 2023-02-28Add `-D`, `--dev` flags for bun install (#2240)Gravatar Justin Whear 1-9/+9 2023-02-28Document punningGravatar Colin McDonnell 1-1/+18