From 50560e169ca39c0b4ec163cb32897baf7620aa69 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 27 Feb 2022 23:20:10 -0800 Subject: WASM --- src/api/demo/pages/index.tsx | 105 ++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 52 deletions(-) (limited to 'src/api/demo/pages/index.tsx') diff --git a/src/api/demo/pages/index.tsx b/src/api/demo/pages/index.tsx index 4d60b4084..7274b3d39 100644 --- a/src/api/demo/pages/index.tsx +++ b/src/api/demo/pages/index.tsx @@ -1,70 +1,71 @@ import Head from "next/head"; import Image from "next/image"; import styles from "../styles/Home.module.css"; -import "../lib/api.ts"; -export default function Home() { +import React from "react"; + +if (typeof window !== "undefined") { + globalThis.Run = await import("../lib/run"); + await import("../lib/api.ts"); +} + +export async function getStaticProps(ctx) { + return { + props: { + code: Bun.readFile( + "/Users/jarred/Build/es-module-lexer/test/samples/magic-string.js" + ), + }, + }; +} + +var textDecoder = new TextDecoder(); +export default function Home({ code }) { + const fileNameRef = React.useRef(); + const [esbuildResult, setEsbuildResult] = React.useState(""); + const [bunResult, setBunResult] = React.useState(""); + const [swcResult, setSWCResult] = React.useState(""); + React.useEffect(() => { + globalThis.Run.start(); + }, []); + + const runBuild = React.useCallback( + (event) => { + globalThis.Run.transform( + event.target.value, + fileNameRef.current.value + ).then((result) => { + setEsbuildResult(result.esbuild.code); + setBunResult(textDecoder.decode(result.bun.files[0].data)); + setSWCResult(result.swc.code); + }, console.error); + }, + [fileNameRef, setEsbuildResult, setBunResult, setSWCResult] + ); return (
- Create Next App + Next.js
-

- Welcome to Next.js! -

- -

- Get started by editing{" "} - pages/index.js -

- -
- -

Documentation →

-

Find in-depth information about Next.js features and API.

-
+
+ + - -

Learn →

-

Learn about Next.js in an interactive course with quizzes!

-
- - -

Examples →

-

Discover and deploy boilerplate example Next.js projects.

-
- - -

Deploy →

-

- Instantly deploy your Next.js site to a public URL with Vercel. -

-
+ + +
- -
); } -- cgit v1.2.3