TypeScript can globally target different versions of Javascript - you can switch between transpiling ES3, ES5 or ES6.
We have to support IE, so ES3 is our lowest common denominator.
However, good browsers (like Chrome) already support ES6, and will be able to run the significantly smaller ES6 code with optimisations.
So, from the same TypeScript source I want to serve ES3 to IE and ES6 to Chrome.
Is there a way to make TypeScript transpile multiple JS files (maybe as *.es3
and *.es6
or something like that) so we can pick which version to serve? (Ideally in VS 2015)
Alternatively in C# can I access the TypeScript transpiler to complete the step at run time?
You can actually specify which version you want to transpile to using the command line (--target ES3
).
You can also specify an output directory, so that you can output both ES6 and ES3 transpiled code, and then chose which to reference on the fly (using old style IE ifs).
How about using different tsconfig.json
files?
For example, something like:
- root
- ts-source
- js-es3
- tsconfig.json
- js
- js-es5
- tsconfig.json
- js
Then the root/js-es3/tsconfig.json
:
{
"compilerOptions": {
"target": "ES3",
"outDir": "js",
"rootDir": "../ts-srouce"
}
}
And the root/js-es5/tsconfig.json
:
{
"compilerOptions": {
"target": "ES5",
"outDir": "js",
"rootDir": "../ts-srouce"
}
}
I'm not a visual studio user so I don't know how to support different tsconfig.json
files there, but even if you can't, then you can compile it using tsc
.
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