Set up a Typescript project to transition from ES6 to ES5 using Bable

I am just starting a new project and I really want to use Async and Await materials that were recently released for typescript.

But it only works (right now) if you focus on ES6.

So, I am wondering if there is a way to configure Visual Studio (upgrade to 2015) to get the ES6 java script that Typescript prints and forwards it to es5?

So, I will have Typescript -> ES6 -> ES5. (This will be in place until Typescript supports ESX Async / Await targeting.)

+4
source share
1 answer

, , , . , . -, http://docs.asp.net/en/latest/client-side/using-gulp.html, gulp VS2015. tsconfig.json typescript :

//tsconfig.json

{
    "compilerOptions": {
        "target": "ES6",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "module": "commonjs",
        "noImplicitAny": false,
        "removeComments": true,
        "preserveConstEnums": true
    },
    "exclude": [
        ".vscode",
        "node_modules",
        "typings",
        "public"
    ]
}

, , gulp - , , ES6 ES5:

// gulpfile.js

'use strict';

var gulp = require("gulp"),
    ts = require("gulp-typescript"),
    babel = require("gulp-babel");

var tsSrc = [
    '**/*.ts',
    '!./node_modules/**',
    '!./typings/**',
    '!./vscode/**',
    '!./public/**'
];
gulp.task("ts-babel", function () {
    var tsProject = ts.createProject('tsconfig.json');
    return gulp.src(tsSrc)
        .pipe(tsProject())
        .pipe(babel({
            presets: ['es2015'],
            plugins: [
                'transform-runtime'
            ]
        }))
        .pipe(gulp.dest((function (f) { return f.base; })));
});

gulp ts-babel. npm, babel-preset-es2015 babel-plugin-transform-runtime.

Upd. Ashok M A . (ts()) (tsProject())

+1

Source: https://habr.com/ru/post/1618661/


All Articles