Node_modules usage/bundler

Hi, I’m trying to develop a fairly complicated script, and know that in order to use modules you can manually copy files over to the Scriptable directory and the like, however I was wondering if anyone has knowledge on getting a esbuild-like bundler tool to work to compile the necessary code into one file. I’ve figured out how to use TypeScript to make development easier (thanks to whoever made @types/scriptable-ios), but I’m kind of stuck now, and don’t want to have to deal with copying node modules.


Edit: Actually, after taking a fresh look at what I was doing, esbuild works just fine. The only problem is that most of the npm modules I was using use node builtin APIs that Scriptable doesn’t support (“fs”, “os”, etc).

I think that browserify could do the job. During building it adds polyfills for all Node.js APIs that are used. But it probably depends on some browser API that is not available in Scriptable. You could run it through a WebView instance though.

I ended up getting browserify working for one of my projects. For anyone else looking for info, you can add the following script to your package.json:

"build": "browserify main.js -s Module > ~/Library/Mobile\\ Documents/iCloud\\~dk\\~simonbs\\~Scriptable/Documents/Module.js"

Calling this script with npm run build builds the module directly in the Scriptable folder. If your main.js file exports anything, it can then be imported using the regular importModule function.

1 Like