Closed jymchng closed 5 days ago
This looks neat!
Hmm, not sure. I would try to fix
TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
first by double checking what mime type your server returns for the WASM file. I somewhat suspect that the WASM file might be missing and that your server returns a HTML error page.
Thank you for your prompt reply.
// `ruffFormatPluginVite` attempts to copy the both files into the browser's assets.
const ruffFormatPluginVite = {
name: "vite-plugin-ruff",
generateBundle: async () => {
const ruffSourceDir = "node_modules/@astral-sh/ruff-wasm-web";
const assetsDir = "dist/assets";
const files = [
"ruff_wasm.js",
"ruff_wasm_bg.wasm",
];
for (const file of files) {
await copyFile(join(ruffSourceDir, file), join(assetsDir, file));
}
},
}
export default defineConfig({
optimizeDeps: { exclude: ["@astral-sh"] },
plugins: [vue(), WindiCSS(), ruffFormatPluginVite], // pyodidePluginVite],
define: {
__API_URL__: JSON.stringify(apiURL),
__PY_VER__: JSON.stringify(pyVer),
__COMMIT__: JSON.stringify(commit),
},
});
I actually copied this from pyodide
and that is how they taught me on how to get the .wasm
binary and .js
shim to be copied into dist/assets
and be made available at runtime within the console.
When I investigate the Sources tab of Chrome, I do realize that they are actually not copied over.
Perhaps, is there a working example, aside from the Ruff playground, to illustrate how one can deploy the Ruff wasm on the frontend?
Thank you.
Perhaps, is there a working example, aside from the Ruff playground, to illustrate how one can deploy the Ruff wasm on the frontend?
Not that I'm aware of. I would expect vite to automatically pick up the dependencies when importing the wasm package.
Yeah I saw the wasm-build command actually calls wasm-pack and dump the built artefacts directly into src
. I guess I shall try the same later. Will update here on how it goes.
Let me know if you're still facing any issues. I close this for now.
I have a not-yet-announced Python Playground.
Within it, I plan to have the [Format] button formatting the
main.py
codes shown on the Left Panel.vite.config.js
ruff.format.js
Here I simply follow the example here and export the
workspace
.Run.vue
Here in
Run.vue
,store.files["main.py"]
is the Python source codes and it is formatted byworkspace
and assigned back tostore.files["main.py"]
.This is the error I got when executing the
npm run dev
.Any idea what's going on?
Thank you.