You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### ASYNC/AWAIT/GENERATORS transformation when targeting ES3/ES5 (without Babel)
45
-
Many TS boilerplates are using Babel transpilation step after the TypeScript compiler output to get support for "async & generator functions transformation" when targeting ES3/ES5. This is costly process and introduces additional build step into the build workflow.
46
-
My solution promote using only [Facebook Regenerator Project](https://github.com/facebook/regenerator) (Babel internally doing the same!) which is executed only when running build for production. Use CLI command `npm run regenerator` after building for production.
45
+
Beware of TypeScript boilerplates using Babel transformation step after the TypeScript compiler to transform "async & generator functions" when targeting ES3/ES5. This is costly process and introduces additional build step into the build workflow.
46
+
- Async/Await - starting from version 2.1 TypeScript provide native support for transformation to ES3/ES5, so in this case you are fine using only TS (https://github.com/Microsoft/TypeScript/pull/9175)
47
+
- Generators - TypeScript Team have dropped adding support for generator transformation to (ES3/ES5) so consider alternative solution covered below (https://github.com/Microsoft/TypeScript/issues/3975#issuecomment-250859415)
47
48
48
-
__NOTE: This is the same as Babel, because Babel is using "regenerator runtime" internally for async/generator functions transformations. So, why in the TS world we shouldn't be doing the same?__
__Alternative solution to resolve Generator transformation to ES3/ES5:__
50
+
My solution promote using [Facebook Regenerator Project](https://github.com/facebook/regenerator) (as Babel internally doing the same!) which is executed only for app.js bundle after building for production.
51
+
Use seperate CLI command `npm run regenerator` to transform app.js generated eariler with `npm run build:app` command, or run an alias command to run it automatically with each build `npm run build:regenerator`.
50
52
51
-
__NOTE (06/10/2016): As TypeScript Team have dropped adding support for downlevel (ES3/ES5) generator transformation in the near future, I believe this is the most optimal solution to use at the moment__
__NOTE: This is the same as Babel, because Babel is using "regenerator runtime" internally for async/generator functions transformations. So, why TS shouldn't be doing the same?__
@@ -217,7 +219,9 @@ __NOTE: Use index.prod.html for production, it have slightly different loading l
217
219
218
220
`npm run build:debug` - build app source code into app.js (dev bundle) - non-minified with source-maps
219
221
220
-
`npm run regenerator` - transpile your app.js through regenerator for async/generator functions when targeting ES3/ES5
222
+
`npm run regenerator` - transform "generator functions" in app.js (prod bundle) to ES3/ES5 using regenerator runtime (not supported natively by TypeScript)
223
+
224
+
`npm run build:regenerator` - alias to run both `npm run build:app` and `npm run regenerator`.
0 commit comments