
EDIT to put some information I gathered at the top for future readers:
- For tsconfig.json, I used target == "ES2019", and module == "None".
- For Webpack, I used globalObject == "this", and libraryTarget == "umd".
- I think a roll20.d.ts file should declare all of roll20's names using "declare global { }". Individual Typescript files should not import anything to account for this file, but should just use the global declarations. It seems like the roll20.d.ts file can then be included like any other source file. It was really hard to find information about this exact situation online (i.e. the situation where the runtime environment provides global symbols).
- I got this done with one monolithic tsconfig.json that built everything; I should have done it that way first!
- I separated Typescript compilation and Webpack packing into two different steps, by telling Webpack to build using the Javascript outputs instead of the Typescript files. This was simpler than fighting with ts-loader errors.
- I think that Webpack is including its own module setup when the Javascript code doesn't have one. Fortunately this doesn't make Roll20 complain and script loading is not noticeably slower than a typical script.
Original question:
I'm looking for a way to set up a Typescript project, optionally with other tools like Webpack, to build multiple Typescript source files in multiple directories into a single script that I can copy-paste into the Roll20 editor. I'm a complete novice to front-end development and this is my first Javascript and my first Typescript project. EDIT: I think that was a mis-statement in terms of the question context.
There are two problems that crop up:
- As far as I can see, Roll20 doesn't support any of the typical module systems, so I need configs for Typescript and the surrounding tools that don't produce *any* module code. (Is there a module system that Roll20 supports, or at least that it will ignore?)
- When an output script is broken, I typically get a SyntaxError with no context of any kind (e.g. "SyntaxError: Unexpected token '.'"). So I really don't have any way to fix it other than blindly changing configs and hoping for the best.
Ideas?
Thanks!