【问题标题】:Ionic 2 + Typescript + Babel (for using async / await with ES5)Ionic 2 + Typescript + Babel(用于在 ES5 中使用 async / await)
【发布时间】:2016-11-08 03:24:00
【问题描述】:

我想在 ionic 2 项目中使用 async/await。由于 ES5 的 async/await 没有适用于 Typescript 2.0:有没有办法配置 ionic 2 应用程序,使 Typescript 将其转换为 ES6(即 async / await 语句不改变),然后由Babel to ES5,让它和不支持async/await的兄弟一起工作?

【问题讨论】:

    标签: typescript ionic-framework ionic2


    【解决方案1】:

    RC 更新:

    从 Ionic RC 开始,旧答案停止工作。 有几种方法可以做到这一点。其中大多数涉及破解节点模块中的构建过程。 最简单的一种是将uglifyjs切换到支持es6的和谐版本。

    node_modules/@ionic/app-scripts/package.json
    

    此文件包含 ionic build 使用的 uglify js。

    将uglify js版本切换为:

    "uglify-js": "git://github.com/mishoo/UglifyJS2.git#harmony
    

    然后在这个文件夹上运行 npm install 就可以了

    离子测试答案

    幸运的是,ionic gulp 提供了此类服务。 你需要的是 babelify 和 ionic-gulp-browesify-typescript-babel 首先从 typescript 切换到 typescript babel 并在你的 package.json 中添加 babelify

    这个

    "ionic-gulp-browserify-typescript": "2.0.0",
    

    到这里

    "babelify": "7.3.0",
    "ionic-gulp-browserify-typescript-babel": "^2.0.2",
    

    现在转到您的 gulpfile.json

    在这里切换你的模块

    var buildBrowserify = require('ionic-gulp-browserify-typescript');
    

    var buildBrowserify = require('ionic-gulp-browserify-typescript-babel');
    

    现在您可以运行 npm install。当您尝试运行该项目时,您很可能会从 babel 收到错误,因为它缺少插件和预设。使用 npm 根据您的需要安装它们。它还会询问您应该安装的 es2015 预设。有关更多信息,您可以查看https://babeljs.io/docs/plugins/

    【讨论】:

      猜你喜欢
      • 2020-05-19
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-03
      • 2017-04-26
      • 2017-05-29
      • 2017-07-13
      相关资源
      最近更新 更多