-->

Transpiling a Polymer Element

2019-08-09 11:16发布

问题:

I'm scaffolding Polymer 1.x Elements using $ polymer init. These elements are not Polymer applications. They are just elements.

All my elements are coded in ES6. I'd like to transpile my elements down to ES5.

Considering that $ polymer build does not support single Element projects, what solutions can I use to achieve the above?

回答1:

Transpiling Polymer to es5 is done in 3 steps:

  1. Vulcanize your element(s) by inlining the script and CSS:

    vulcanize element.html --inline-script --inline-css > element.v.html

  2. Pipe the output to Cripser. Crisper is a tool that extracts all inline and creates a standalone .js file.

    crisper -s element.v.html -h element.v.html -j element.js

  3. Run the standalone JS file through Babel:

    babel element.js -o element.js

Old Answer(wrong):You need to use vulcanize directly. for instance:

 vulcanize target.html > build.html