@wetteyve/rusty
v0.0.6
Published
Node package with napi-rs
Maintainers
Readme
@wetteyve/rusty
A Rust-powered utility package built with napi-rs, focused on experimentation, learning, and cross-platform native & WASM development.
napi-rs • nodeJS • Rust • WASM
📚 Docs
Installation
Install with your package manager of choice:
yarn add @wetteyve/rustyVite Configuration (Optional)
If you are using Vite, you need to exclude the package from the dependency optimization:
// vite.config.js
import { defineConfig } from 'vite';
export default defineConfig(() => ({
...,
optimizeDeps: {
exclude: [ ...,'@wetteyve/rusty'],
},
...
}));Node.js Server Runtime
When running in a Node.js server environment, no special configuration is required. Simply import the package and use it directly:
import { helloNapi } from '@wetteyve/rusty'
console.log(helloNapi('rusty')) // → Hello, rusty!Client-Side Usage (WASM)
- To use the package in the browser, follow the settings for your package manager here.
- You'll need to load the WASM module asynchronously in the client:
Example with react-router:
import { type Route } from './+types/home';
// Setup WASM in client browser
export const clientLoader = async ({ serverLoader }: Route.ClientLoaderArgs) => {
const [serverData, rusty] = await Promise.all([
serverLoader(),
import('@wetteyve/rusty'), // Load WASM asynchronously
]);
return { ...serverData, rusty };
};
clientLoader.hydrate = true;
export const HydrateFallback = () => <p>Loading...</p>;
const App = ({ loaderData: { rusty } }: Route.ComponentProps) => (
<div>
<button onClick={() => window.alert(rusty.helloNapi('WASM'))}>Hello WASM!</button>
</div>
);
export default App;This setup ensures the WASM functionality is properly loaded and accessible on the client-side. Adjust paths and logic according to your app structure.
