I have tried to find a suitable approach for this "problem" but was not able to (yet), so thought, that I could ask here. Any advise would be appreciated.
I have a project in PHPStorm, which has some TypeScript code structures like this:
At the moment I use tsconfig.json to merge all the .ts files to main.js and then use a file watcher to minify it using Terser. This works totally fine, but I would like to utilize ES6 modules and with that I am hitting a wall.
In the current setup, scripts that are in `Pages` directory are supposed to be modules, while the rest of the codebase is `Common`, that is it's needed to be loaded on every page. In order to reduce number of HTTP requests, I want all the files in `Common` to be merged into 1 file. Obviously, it's quite easy to do with tsconfig.json, but then I am unable to utilize the modules, I have to merge them as well.
I have tried the following:
1. Use the same setup, but set
in tsconfig. TypeScript complains, that I can't use `outFile` in such case.
2. Tried not using `outFile` - it results in compilation of each script separately. And technically I can use that: use terser to merge all JS files in `Common` and that's it, but in that case I loose source maps, because it does not look possible to feed several source maps to Terser. Which obviously complicates debugging, which I do not want.
3. Tried having 2 tsconfig files: one for `Common` with no modules and with `outFile`, the other one for `Pages` files without `outFile` but with ES6 for `module`. But this does not work because tsconfig for `Common` does not list the modules from `Pages`, thus it fails on lines referencing them and since tsconfig for `Pages` does not refer any files from `Common`, the modules fail on helper function or global variables, because they do not see them.
I am pretty sure, that this is something basic and I am missing something obvious here, but perhaps someone can advise what would possible approaches to having `Common` merged into single JS file, and `Pages` compiled as separate ones, but so that they could "see" each other still?
Hopefully I've explained clearly enough, but if not - I am ready to clarify, of course.
Thanks in advance.