sysgears / spinjs

SpinJS is now Zen! The project has been renamed and moved to Larix Framework.
https://github.com/sysgears/larix/tree/master/packages/zen
MIT License
43 stars 8 forks source link

Typescript target ES2016 doesn't work in IE11 #28

Closed wojcikiewiczm closed 5 years ago

wojcikiewiczm commented 5 years ago

Hi, I have a little problem. I have to have in tsconfig target es2016 (because of some plugin) but IE 11 doesn't support es2016 features. So I have a question if It's possible to somehowe transpile from typescript es2016 via babel back to es5. Thanks

larixer commented 5 years ago

@wojcikiewiczm TypeScript compiler transpiles code to the target that you specify. You kinda contradict youself, if you need es5 target, specify this in tsconfig.json, if you sepcified es2016 as a target, no wonder that you end up with transpiled code for es2016

larixer commented 5 years ago

@wojcikiewiczm Specify "lib": ["es2016"] and "target": "es5"in tsconfig.json if you want to transpile to es5 but use features of es2016

wojcikiewiczm commented 5 years ago

@vlasenko Thanks but that's the problem. I have to compile typescript to ES6 (ES2015) because of Classes on backend (https://github.com/RobinBuschmann/sequelize-typescript) but I need to have frontend as ES5 beacuse of IE 11 (IE 11 doesn't know classes). I'm using your apollo starter kit and I think I need something like TS -> ES6 -> Babel -> ES5. It's possible somehow? I tried to setup babel rc in many ways but none of them worked. And I think that it's beacuse now it works like this Babel -> ES5 -> TS -> ES6. Thanks

wojcikiewiczm commented 5 years ago

@vlasenko Ok I managed to fix it! Solution was simple. Just replace ts-loader with awesome-typescript-loader (So just uninstall ts-loader and install recent awesome-typescript-loader) and then just place into tsconfig.json this ->

    "useBabel": true,
    "babelOptions": {
      "babelrc": false,
      "presets": [
        [
          "@babel/preset-env",
          {
            "targets": "last 2 versions, ie 11",
            "modules": false
          }
        ]
      ]
    },
    "babelCore": "@babel/core",
    "reportFiles": [
      "**/*.ts",
      "**/*.tsx"
    ]
  }

This will transpile ES6 back to ES5

larixer commented 5 years ago

@wojcikiewiczm Great, thanks for letting know!