nwb is getting a new boolean runtime
option which triggers use of babel-plugin-transform-runtime
I think it also needs a polyfill
option to control polyfilling, as babel-plugin-transform-runtime
is also related to polyfilling (see below)
(polyfill
could also be used to automatically include babel-polyfill
for apps when configured to do so)
Always:
- Imports small helpers like
_extend
frombabel-runtime
instead of duplicating them in every module they're needed in
By default, with an option to turn off, it also:
- Imports the
regenerator
runtime into the current module whenasync
/await
syntax is used. - Polyfills new built-ins like
Promise
,Set
,Symbol
and new static methods likeObject.assign()
locally rather than globally (suitable for libraries)
Polyfills new built-ins, static methods and instance methods globally and provides the regenerator
runtime globally (suitable for apps)
Goal: determine which preconfigured preset we should use from deduped-babel-presets
given runtime
and polyfill
user config (and add new preset to it as necessary)
if runtime:
# If polyfilling is not explicitly enabled, only import helpers and the
# regenerator runtime as needed.
runtime_preset = 'runtime-regenerator'
# We should require that polyfilling is explicitly enabled
if polyfill == 'global:'
# Only import helpers, as regenerator and polyfills will already be in
# place via babel-polyfill
runtime_preset = 'runtime-helpers'
elif polyfill == 'local':
# Use all runtime transform features
runtime_preset = 'runtime'
What if we also allow polyfill: true
and change what it corresponds to based on whether we're building an app or a component? (You're never expected to switch between app types in the same project)
Too magical/confusing?
- app:
polyfill == true → 'global'
- component/other npm module:
polyfill == true -> 'local'
What if you want to publish a component which requires that users provide a suitable regenerator
runtime - too much?