I would like to use babel-standalone (https://babeljs.io/docs/en/next/babel-standalone.html) with typescript.
I tried:
const output = Babel.transform(input, { presets: ['typescript'] }).code;
And:
<script type="text/babel" data-presets="typescript">
But nothing seems to work
I'm loading Babel in my app using: https://unpkg.com/@babel/standalone/babel.min.js
I have only tested this with embedded javascript v8 in a C++ project. In order to transpile typescript with Babel standalone, a filename must be specified in the settings passed to Babel.transform, otherwise a javascript error is thrown from Babel about the missing filename.
const output = Babel.transform(
input,
{
"presets": ["typescript"],
"filename": "example.ts"
}
).code;
The filename doesn't have to refer to a real file. However the file extension must be .ts for the typescript transpiler to be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With