Skip to content

Commit

Permalink
Include regenerator-runtime in standalone build
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Dec 21, 2019
1 parent c340f41 commit 53c74e8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions babel.config.js
@@ -1,5 +1,7 @@
"use strict";

const path = require("path");

module.exports = function(api) {
const env = api.env();

Expand All @@ -14,6 +16,10 @@ module.exports = function(api) {

let convertESM = true;
let ignoreLib = true;
let includeRegeneratorRuntime = false;

let transformRuntimeOptions;

const nodeVersion = "6.9";
// The vast majority of our src files are modules, but we use
// unambiguous to keep things simple until we get around to renaming
Expand Down Expand Up @@ -45,8 +51,11 @@ module.exports = function(api) {
case "standalone":
convertESM = false;
ignoreLib = false;
includeRegeneratorRuntime = true;
// rollup-commonjs will converts node_modules to ESM
unambiguousSources.push(
"**/node_modules",
// todo: remove this after it is rewritten into ESM
"packages/babel-preset-env/data"
);
// targets to browserslists: defaults
Expand All @@ -70,6 +79,17 @@ module.exports = function(api) {
break;
}

if (includeRegeneratorRuntime) {
const babelRuntimePkgPath = require.resolve("@babel/runtime/package.json");

transformRuntimeOptions = {
helpers: false, // Helpers are handled by rollup when needed
regenerator: true,
version: require(babelRuntimePkgPath).version,
absoluteRuntime: path.dirname(babelRuntimePkgPath),
};
}

const config = {
// Our dependencies are all standard CommonJS, along with all sorts of
// other random files in Babel's codebase, so we use script as the default,
Expand Down Expand Up @@ -127,6 +147,10 @@ module.exports = function(api) {
test: unambiguousSources,
sourceType: "unambiguous",
},
includeRegeneratorRuntime && {
exclude: /regenerator-runtime/,
plugins: [["@babel/transform-runtime", transformRuntimeOptions]],
},
].filter(Boolean),
};

Expand Down

0 comments on commit 53c74e8

Please sign in to comment.