Skip to content

Commit

Permalink
Fix rollup build
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 10, 2020
1 parent 2909d4e commit bfe45e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gulpfile.js
Expand Up @@ -183,6 +183,7 @@ function buildRollup(packages) {
rollupCommonJs({
include: [
/node_modules/,
"packages/babel-runtime/regenerator/**",
"packages/babel-preset-env/data/*.js",
// Rollup doesn't read export maps, so it loads the cjs fallback
"packages/babel-compat-data/*.js",
Expand Down
13 changes: 4 additions & 9 deletions babel.config.js
@@ -1,7 +1,5 @@
"use strict";

const path = require("path");

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

Expand Down Expand Up @@ -35,21 +33,19 @@ module.exports = function(api) {

switch (env) {
// Configs used during bundling builds.
case "rollup":
envOpts.targets = {
node: nodeVersion,
};
case "standalone":
includeRegeneratorRuntime = true;
unambiguousSources.push("packages/babel-runtime/regenerator");
case "rollup":
convertESM = false;
ignoreLib = false;
includeRegeneratorRuntime = true;
// rollup-commonjs will converts node_modules to ESM
unambiguousSources.push(
"**/node_modules",
"packages/babel-preset-env/data",
"packages/babel-compat-data"
);
// targets to browserslists: defaults
if (env === "rollup") envOpts.targets = { node: nodeVersion };
break;
case "production":
// Config during builds before publish.
Expand Down Expand Up @@ -77,7 +73,6 @@ module.exports = function(api) {
helpers: false, // Helpers are handled by rollup when needed
regenerator: true,
version: require(babelRuntimePkgPath).version,
absoluteRuntime: path.dirname(babelRuntimePkgPath),
};
}

Expand Down
15 changes: 11 additions & 4 deletions scripts/rollup-plugin-babel-source.js
Expand Up @@ -37,13 +37,20 @@ module.exports = function() {
return null;
},
resolveId(importee) {
let packageFolderName;
if (importee === "@babel/runtime/regenerator") {
return path.join(
dirname,
"packages",
"babel-runtime",
"regenerator",
"index.js"
);
}

const matches = importee.match(/^@babel\/([^/]+)$/);
if (matches) {
packageFolderName = `babel-${matches[1]}`;
}
const packageFolderName = `babel-${matches[1]}`;

if (packageFolderName) {
// resolve babel package names to their src index file
const packageFolder = path.join(dirname, "packages", packageFolderName);
const packageJson = require(path.join(packageFolder, "package.json"));
Expand Down

0 comments on commit bfe45e2

Please sign in to comment.