I currently have a preload.js
script that basically adds variables to the window
object for a webview. What I want to do is import a typescript file inside the preload script. The preload only supports commonjs syntax.
Is there any way I can achieve this?
I tried to transpile the file and access the webpack output but it didn't work.
So, the best solution I found was using an external package. First I did publishing it to npm and now I'm using yarn workspaces
and simply requiring my package inside preload.js
const = { MyClass } = require('my-workspace-package')
and then I can use it freely inside the file (and also inject it into my window
object for instance)