ts-browser icon indicating copy to clipboard operation
ts-browser copied to clipboard

make ts-browser self contained

Open rdlaitila opened this issue 4 years ago • 6 comments

If I copy ts-browser down to my project locally, and load the module as so:

<script type="module">
        import {loadModule} from './ts-browser/src/ts-browser.js';
        loadModule('./index.ts');
</script>

It still calls out to various klesun urls to pull down worker scripts and ts compiler js:

https://github.com/klesun/ts-browser/blob/cd85cdc95e87aa0850af93cef9f186e840e1bae4/src/TranspileWorker.js#L3

https://github.com/klesun/ts-browser/blob/cd85cdc95e87aa0850af93cef9f186e840e1bae4/src/cdnEs6Wrappers/typescriptServices.js#L12

possibly other places too. Is it possible to make ts-browser self contained so I have no external dependence on your hosted urls?

Edit: I should add this is a very cool project!

rdlaitila avatar Jun 22 '20 20:06 rdlaitila

Hi, good point, most likely just me being lazy. Will try to patch it shortly.

klesun avatar Jun 23 '20 05:06 klesun

Gosh, those workers are such a pain...

klesun avatar Jun 23 '20 08:06 klesun

Created a PR that seems to get this working. I am running a local webserver to serve everything and ts-browser is installed in my web root as a folder 'ts-browser'.

The changes are likely not comprehensive but its a start.

rdlaitila avatar Jun 23 '20 13:06 rdlaitila

I fixed local scripts being fetched via absolute links in 8b20707e7deaa932eee8658c8de64c0121213097, that was very stupid, but wasn't obvious to me at the moment of initial writing how to avoid that.

In most places, declaring window.ts and window.md5 with versions of the libs of your choice before calling ts-browser should save you from fetching them from cdn. Not a very 2k20 solution, but should still work supposedly...

Making the url of typescriptServices.ts fetched inside the worker configurable would be a nice thing, but would require some refactoring, as currently workers are initialised instantly on module level for optimisation, without any means to pass parameters from loadModule()

klesun avatar Jun 23 '20 21:06 klesun

Also got rid of remaining klesun url-s - using unpkg.com for typescriptServices.js instead - 0c7645526117ea73a799cd52246406e5b05e30aa

klesun avatar Jun 23 '20 22:06 klesun

And also published it on npm =3 https://www.npmjs.com/package/ts-browser-klesun

klesun avatar Jun 23 '20 22:06 klesun