R
R
Roman Kitaev2018-11-21 16:27:18
JavaScript
Roman Kitaev, 2018-11-21 16:27:18

Should I include regenerator-runtime in the module's dist?

Hey! I'm writing an npm module for general use at work. The module uses async/await. Also in the module is, as is customary, a bundle compiled and transpiled by babel in /dist. That is, in this bundle, async / await are translated into regeneratorRuntime.wrap / mark
Question - should I include regeneratorRuntime in the bundle?
There are three options that I know and don't like:

  1. Include regeneratorRuntime in the bundle.
    Pros:
    • Connected and working
    • Clean webpack config

    Minuses:
    • Overhead space occupied +7kb for each module. Common Chunks don't work because it's already a pre-built bundle. In total, if there are 20 modules, there will be 140kb of regenerators, although one is enough.

  2. The concern is shifted to the programmer. In the documentation, we write that a regenerator is needed to work. The programmer himself puts the regenerator in any way he likes
    Pluses:
    • Clean architecture
    • No overhead

    Minuses:
    • Possible setup complexity

  3. Throwing dist from the package, compiling the package when building the project
    Pros:
    • Even cleaner architecturally (no dist compiled specifically by babel)
    • babel or its analogue, or even its absence (suddenly the target is es6) itself understands when it is necessary to turn on the regenerator, and when not

    Minuses:
    • Even more difficult to set up. For example, in webpack, you will need to specify exceptions from node_modules that need to be run by babel. And connect the transform-runtime plugin to babel

    In fact, there is a fourth option - to rewrite all async / await in the module to promises, but I like it even less.
    To reiterate my question: which way (perhaps not listed) is the best way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question