LimeStreem LimeStreem - 1 year ago 135
TypeScript Question

How can I make babel generating polyfills like `__createClass` just a one time for multiple files?

My project containing many ES6 files and all of these are containing at least one class.

polyfilling function are generated for each files.
I would concat them with browserify after that, and I guess it is too redundant to keep them for all of files.
I think I can inject polyfilling functions during bundling task.

When I use typescript, I can specify
options not to generate such codes during compiling task. Is there something way to do that with babel?

Answer Source

You can use babel-plugin-transform-runtime. It does exactly what you're looking for. Check out the docs.

This is where the transform-runtime plugin comes in: all of the helpers will reference the module babel-runtime to avoid duplication across your compiled output. The runtime will be compiled into your build.

$ npm install --save-dev babel-plugin-transform-runtime 
$ npm install --save babel-runtime


  "plugins": ["transform-runtime"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download