Skip to content

Conversation

@thejustinwalsh
Copy link

Optionally you can pass compilerOptions to the TypeScript transpiler:

<script type="text/typescript" data-compiler-options='{ "target": "es5", "module": "none"}' src="script.ts"></script>
<script type="text/typescript">
    setTimeout(()=>console.log('hello'));
</script>

If you are not using a module loader and just need a quick hack if you attempt to export from your module add this to the bottom instead:

<script>var exports = {};</script>
<script src="https://raw.githack.com/Microsoft/TypeScript/master/lib/typescriptServices.js"></script>
<script src="https://raw.githack.com/basarat/typescript-script/master/transpiler.js"></script>

TODO

Optionally you should be able to tell the transpiler service to generate es module script tags for a complete solution without a hack, if desired I could add this to this PR or add another PR, functional as is without this extra sugar.

<script type="text/typescript" data-compiler-options='{ "target": "es5" }' data-type="module" src="script.ts"></script>
<!-- would generate this -->
<script type="module">
//Compiled Typescript
...
</script>

i.e. `data-compiler-options='{ "target": "es5", "module": "none"}'`
Add an example of how to use the `data-compiler-options` attribute
Add hack about using modules

TODO: Optionally you should be able to tell the transpiler service to generate es module script tags for a complete solution without a hack...
```html
<script type="text/typescript" data-compiler-options='{ "target": "es5" }' data-type="module" src="script.ts"></script>
<!-- would generate this -->
<script type="module">
//Compiled Typescript
...
</script>
```
@thejustinwalsh
Copy link
Author

If #12 is accepted as well, I can submit a PR with the two combined, or based on one another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant