Using generators/async-await etc. without modular bundler
See original GitHub issueI’m not sure if this is the best place to ask, but here goes…
The documentation for this package says that,
If you’re attempting to use features such as generators, you’ll need to add
transform-runtime
as a plugin, to include the Babel runtime. Otherwise, you’ll receive the error:regeneratorRuntime
is not defined.
Unfortunately, as noted in several previous issues this just yields the error “require
is not defined” because:
This does not work because Babel does not handle module bundling. Generally you’d use
gulp-babel
to compile files that would be loaded in Node, which has its own module loader. To bundle code like this for a browser you’d want to use Webpack. — loganfsmyth
But Webpack, Browserify, Node module bundlers, etc. are not for everyone. Personally, I have no interest in having to set up complex module bundlers for every new project – especially not when they’re completely unnecessary, except for this one tiny aspect.
Is there some way to use gulp-babel
to transpile ES6 to ES5 with these features, but without using a module bundler, yielding transpiled JS files that can be used as-is in a browser?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6 (2 by maintainers)
Top GitHub Comments
You can add
<script src="https://unpkg.com/browse/regenerator-runtime@0.13.4/runtime.js"></script>
to your HTML file, before loading your JavaScript code. Then you don’t needtransform-runtime
, which requires a bundler.plugins: [ ['@babel/transform-runtime'] ]