Replies: 2 comments 1 reply
-
I tried a different approach by writing a quick and dirty Vite plugin to transform the code using the actual ruby2js gem directly. The difference is remarkable as the time to build dropped from about 10 minutes to around 20 seconds. I'm thinking that the Opal translation of the parser code is pretty inefficient and that converting all the code to JS first is a nice idea, but doesn't work very well. Of course, you need Ruby in your build environment, but that shouldn't be a big hurdle. Here's my sample Vite plugin const ruby2js = () => ({
name: 'ruby2js',
transform(code, id) {
let transformCode = code;
let map = null;
if (id.endsWith('.rb')) {
let child = spawnSync(`ruby2js --es2022 --autoexports true --underscored_private --identity --sourcemap --filter esm --filter functions --filter camelCase --filter active_functions ${id}`, { shell: true });
const result = JSON.parse(child.stdout.toString());
transformCode = result["code"];
map = result["sourcemap"];
}
return { code: transformCode, map }
}
}) |
Beta Was this translation helpful? Give feedback.
-
At the moment, as you can see, the options are all hard-coded and these would need to be generalized in order to make it fully useful as a plugin. It's certainly something I can have a look at doing. |
Beta Was this translation helpful? Give feedback.
-
Is there some trick to building ruby2js? I've got a few largish ruby files that I'm trying to convert as part of a Vite build and it's taking an inordiate amount of resources to build. For example, sitting on 22GB memory at 100% CPU for 10 minutes!
So I attempted to build the ruby2js.js file with mixed success. I upgraded to the latest opal and found there was a problem with the sourcemap code. I resolved that, but then ended up with a crash in the parser code with the sample 'puts "2A".to_i(16)' when testing the rollup package. This crash is in the parser gem and is still there when rolling back to the original opal version.
What level of the parser gem was used in the build?
I was hoping to be able to build a running package that I could put some debugging in tofind out where the time is going, but I can't seem to build anything that actually runs.
Any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions