felixSchl / photoshop.d.ts

Typescript declaration files and generator for the Photoshop javascript API
Other
78 stars 9 forks source link

Requirejs instructions in readme.md #22

Closed peternepp closed 4 years ago

peternepp commented 4 years ago

I'm really interested in how to use 'real' modules with Typescript/ExtendScript.

@felixSchl In readme.md you mentioned that it is possible via requirejs:

Note: If you want to use modules in ExtendScript, you need a module loader like requirejs and set the module option to "amd". The setup of requirejs for ExtendScript requires some configuration.

I'm curios what configuration that might be? Can you describe that a little more please?

Thanks a lot, Peter

perludum commented 4 years ago

It’s some time ago I’ve used that kind of setup with requirejs, but I’ll try to reconstruct how to use it (the readme was updated by me back then). Attached you can find an (unfinished) boilerplate extension I had once begun which also uses requirejs. Can’t tell if and how it currently compiles, but the app.jsx still executes fine in PS 2020 with a module loaded by requirejs.

I think the trick was to append requirejs module loading at last in code and by exposing the loaded modules to global space. I hope you can figure it out with the attached example.

Here are some more links with different explanations on how to use requirejs in conjunction with typescript: https://www.stevefenton.co.uk/2013/02/using-requirejs-and-jquery-in-typescript/ https://medium.com/@kulor/typescript-and-requirejs-442be2043833 https://stackoverflow.com/questions/14587720/using-requirejs-alongside-non-amd-javascript-files

The technique seems to be similar except that I had put module loading with requirejs into a separate expose.js file. extension.zip

peternepp commented 4 years ago

@perludum Many thanks for the information. I'll have a look at it.