I'm working with custom elements. A lot of these (especially libraries like Polymer) use HTML imports to load the component.
Most elements involve some CSS, some HTML and some scripts, and these can be separate .css and .js/.ts, often with embedded HTML in strings (or React/Preact .tsx files).
There's a more elegant solution using HTML imports:
<link rel="import" href="my-component.html">
And then in my-component.html:
...
<template>
<style>
...
</style>
<p>HTML content!</p>
</template>
<script>
// Javascript to create custom element
</script>
...
I can use TypeScript externally with a separate .ts file, but that's a little messy. What I want to do is replace my-component.html with my-component.tshtml - a file that looks almost identical, but that has TypeScript instead of Javascript and that transpiles to the .html version in exactly the same way as .ts or .tsx files.
Is there any way to do this?
.tsfile and then have a post-build step that inserted it into the.htmlfile, but that the bit I refer to as messy in the question. I'm looking for a better way.