vdesjs / vite-plugin-monaco-editor

A vite plugin for the Monaco Editor
MIT License
206 stars 36 forks source link

Would it be possible to support SharedWorkers? #16

Closed okikio closed 2 years ago

okikio commented 2 years ago

Monaco uses up a lot of memory, so, I prefer to put workers in SharedWorkers. For the astro playground, I used SharedWorkers to limit memory usage and ensure that multiple monaco editors can still work properly, you check out how I used it here https://github.com/snowpackjs/astro-repl/blob/741460dfcbe894473f8e66153926cc653d0fe8b9/src/editor/modules/monaco.ts#L258

Would it be possible to support SharedWorkers?

NomadBin commented 2 years ago

You can try to use the use the customWorkers options to specified absolute path:

 monacoEditorPlugin({
            customWorkers: [
                {
                    label: "share",
                    entry: path.resolve(__dirname, "src/worker/share.worker")
                }
            ]
        })
okikio commented 2 years ago

Thank you, I truly appreciate it. You might want to add to the readme that you can use SharedWorkers.

NomadBin commented 2 years ago

The new SharedWorker(/* ... */) should be write into the file src/worker/share.worker