ecmascript 6 - ES6 Generator functions cause error: Uncaught ReferenceError: regeneratorRuntime is not defined -
if put generator function like
function* somewords() { yield "hello"; yield "world"; } (var word of somewords()) { alert(word); }
in app.js, code produces uncaught reference error.
if run same code within script tag in app.html.eex, runs fine.
the code in app.html.eex
not passed through babel. if using browser supports generators work.
since app.js
code transpiled babel, need use https://babeljs.io/docs/usage/polyfill/ generators work.
app.js
import "phoenix_html" import "babel-polyfill" function* somewords() { yield "hello"; yield "world"; } (var word of somewords()) { alert(word); }
brunch_config.js
exports.config = { files: { javascripts: { jointo: "js/app.js" }, stylesheets: { jointo: "css/app.css" }, templates: { jointo: "js/app.js" } }, conventions: { assets: /^(web\/static\/assets)/ }, paths: { watched: [ "web/static", "test/static" ], public: "priv/static" }, plugins: { babel: { // not use es6 compiler in vendor code ignore: [/web\/static\/vendor/] } }, modules: { autorequire: { "js/app.js": ["web/static/js/app"] } }, npm: { enabled: true, whitelist: ["phoenix", "phoenix_html", "babel-polyfill"] } };
package.json
{ "repository": {}, "dependencies": { "babel-brunch": "^6.0.0", "babel-polyfill": "^6.3.14", "brunch": "^2.1.3", "clean-css-brunch": ">= 1.0 < 1.8", "css-brunch": ">= 1.0 < 1.8", "javascript-brunch": ">= 1.0 < 1.8", "phoenix": "file:deps/phoenix", "phoenix_html": "file:deps/phoenix_html", "uglify-js-brunch": ">= 1.0 < 1.8" } }
Comments
Post a Comment