Browse guides

Create a local TSX project

Move from the browser-only document to a local TSX project with a generated bundle.

The sequence installs the package, configures automatic TSX, builds `dist.js` and opens the mounted greeting.

Table of contents

Main APIs

mount
Starts a Valyrian.js application on a DOM target.
inline
Bundles build input for server-side tooling.

1. Install

Create the project and install Valyrian.js.

bash
mkdir my-valyrian-app
cd my-valyrian-app
npm init -y
npm install valyrian.js

2. Configure TSX

Create tsconfig.json so TypeScript resolves the automatic TSX runtime from Valyrian.js.

json
{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "valyrian.js"
  }
}

3. Create the browser entry

Create index.tsx with the same mount flow used by the CDN path.

tsx
import { mount } from "valyrian.js";

function App() {
  return <main>Hello from local Valyrian.js</main>;
}

mount("body", App);

4. Create the build script

Create build.mjs. inline bundles index.tsx and resolves { raw, map, file }. Write raw to dist.js. Unknown file types and transformation failures reject the call.

js
import fs from "node:fs";
import { inline } from "valyrian.js/node";

const result = await inline("./index.tsx", { compact: true });
fs.writeFileSync("./dist.js", result.raw);
console.log("Built dist.js");

5. Load the bundle

Create index.html beside dist.js so the browser loads the generated bundle.

html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Valyrian.js App</title>
  </head>
  <body>
    <script src="./dist.js"></script>
  </body>
</html>

6. Build and run

Build the entry, start the pinned Node.js static server at http://localhost:8000 and open that URL. The page should show Hello from local Valyrian.js.

bash
node build.mjs
npx --yes serve@14.2.5 . --listen 8000

Result

After the build completes, open the served page and confirm that it shows Hello from local Valyrian.js.

Continue the cumulative application

Exact references