Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to wasm-pack build --target bundler and Vite plugins for loading WebAssembly component #75

Merged
merged 5 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WORKDIR /home/rust/src
RUN apk --no-cache add curl musl-dev
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
COPY . .
RUN wasm-pack build --target web rustpad-wasm
RUN wasm-pack build rustpad-wasm

FROM --platform=amd64 node:lts-alpine AS frontend
WORKDIR /usr/src/app
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ To run this application, you need to install Rust, `wasm-pack`, and Node.js.
Then, build the WebAssembly portion of the app:

```
wasm-pack build --target web rustpad-wasm
wasm-pack build rustpad-wasm
```

When that is complete, you can install dependencies for the frontend React
Expand All @@ -60,7 +60,7 @@ to start the frontend portion.
npm run dev
```

This command will open a browser window to `http://localhost:3000`, with hot
This command will open a browser window to `http://localhost:5173`, with hot
reloading on changes.

## Testing
Expand Down
270 changes: 269 additions & 1 deletion package-lock.json

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

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"monaco-editor": "^0.31.1",
"prettier": "2.5.1",
"typescript": "~5.5.3",
"vite": "^5.3.4"
"vite": "^5.3.4",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0"
},
"overrides": {
"@swc/core": "~1.6.13"
}
}
21 changes: 9 additions & 12 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { StrictMode } from "react";
import ReactDOM from "react-dom";
import { ChakraProvider } from "@chakra-ui/react";
import init, { set_panic_hook } from "rustpad-wasm";
import * as wasm from "rustpad-wasm";
import App from "./App";
import "./index.css";

init().then(() => {
set_panic_hook();
ReactDOM.render(
<StrictMode>
<ChakraProvider>
<App />
</ChakraProvider>
</StrictMode>,
document.getElementById("root")
);
});
ReactDOM.render(
<StrictMode>
<ChakraProvider>
<App />
</ChakraProvider>
</StrictMode>,
document.getElementById("root")
);
8 changes: 7 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { defineConfig } from "vite";
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
import react from "@vitejs/plugin-react";

export default defineConfig({
build: {
chunkSizeWarningLimit: 1000,
},
plugins: [react()],
plugins: [
wasm(),
topLevelAwait(),
react()
],
server: {
proxy: {
"/api": {
Expand Down
Loading