Skip to content

Commit

Permalink
Switch to wasm-pack build --target bundler and Vite plugins for loa…
Browse files Browse the repository at this point in the history
…ding WebAssembly component

Fixes dev-mode. This makes use of native Vite capabilities to load the
WebAssembly component and appears to be the recommended approach nowadays.

See: rustwasm/wasm-pack#1106 (comment)
  • Loading branch information
ntninja committed Jul 18, 2024
1 parent cf94862 commit e131070
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 23 deletions.
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 amd64/node:lts-alpine AS frontend
WORKDIR /usr/src/app
Expand Down
2 changes: 1 addition & 1 deletion 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 Down
278 changes: 271 additions & 7 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"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"
}
}
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")
);
Loading

0 comments on commit e131070

Please sign in to comment.