Skip to content

Commit

Permalink
- Rename src to source
Browse files Browse the repository at this point in the history
- Add middleware to redirect WASM request to node_modules
  • Loading branch information
krollins-mdb committed Jul 24, 2024
1 parent 8ddc0ef commit d258a6d
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 68 deletions.
18 changes: 14 additions & 4 deletions examples/frameworks/react-test-app/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="icon"
type="image/svg+xml"
href="/vite.svg"
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script
type="module"
src="/source/main.tsx"
></script>
</body>
</html>
70 changes: 10 additions & 60 deletions examples/frameworks/react-test-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion examples/frameworks/react-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"dependencies": {
"@realm/react": "^0.9.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"realm-web": "^2.0.1"
"realm": "12.0.0-browser.2"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/frameworks/react-test-app/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["source"]
}
29 changes: 27 additions & 2 deletions examples/frameworks/react-test-app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import { defineConfig } from "vite";
import { defineConfig, Plugin } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import { promises as fs } from "fs";

const wasmContentTypePlugin: Plugin = {
name: "wasm-content-type-plugin",
configureServer(server) {
server.middlewares.use(async (req, res, next) => {
if (req.url && req.url.endsWith(".wasm")) {
res.setHeader("Content-Type", "application/wasm");

const wasmPath = path.join(
__dirname,
"node_modules/realm/dist",
path.basename(req.url)
);
const realmWasm = await fs.readFile(wasmPath);

res.write(realmWasm);
res.end();
} else {
next();
}
});
},
};

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [react(), wasmContentTypePlugin],
esbuild: {
supported: {
"top-level-await": true,
Expand Down

0 comments on commit d258a6d

Please sign in to comment.