I'm experimenting with the new rc-release of TypeScript to get the asnc/await support for ES5.
But I experience a strange behavior with the generated __awaiter and __generator methods, it seems they are generated for every single ts file if the outFile compiler option is not used.
Is there a way to generate only a single instance of the __awaiter and __generator methods while still not using outFile? The reason why I don't want to use the outFile flag is that I currently use webpack for bundling as I need to support importing of HTML template files.
Use the new --importHelpers
compile flag.
Docs
In tsconfig.json, under "compilerOptions"
add:
`"importHelpers": true`
install the typescript helper library as a dependency:
npm install tslib --save
Typescript will attempt to import the helpers when needed and Webpack will automatically bundle tslib once. If you are publishing a library you can tell webpack to consider tslib
an external with the externals
option.
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