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. -->