diff --git a/babel.config.js b/babel.config.js index 34a382f130ab..2715d650aa35 100644 --- a/babel.config.js +++ b/babel.config.js @@ -11,6 +11,7 @@ module.exports = function(api) { exclude: ["transform-typeof-symbol"], }; const envOpts = Object.assign({}, envOptsNoTargets); + let transformRuntimeOpts = null; let convertESM = true; let ignoreLib = true; @@ -50,6 +51,17 @@ module.exports = function(api) { break; } + if (includeRuntime) { + const babelRuntimePackageJSONPath = require.resolve( + "@babel/runtime/package.json" + ); + const path = require("path"); + transformRuntimeOpts = { + version: require(babelRuntimePackageJSONPath).version, + absoluteRuntime: path.dirname(babelRuntimePackageJSONPath), + }; + } + 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, @@ -123,10 +135,7 @@ module.exports = function(api) { ], plugins: [ includeRuntime - ? [ - "@babel/transform-runtime", - { version: require("@babel/runtime/package").version }, - ] + ? ["@babel/transform-runtime", transformRuntimeOpts] : null, ].filter(Boolean), }, diff --git a/packages/babel-core/package.json b/packages/babel-core/package.json index 4da69a87d404..f22326d78eb3 100644 --- a/packages/babel-core/package.json +++ b/packages/babel-core/package.json @@ -34,7 +34,9 @@ }, "browser": { "./lib/config/files/index.js": "./lib/config/files/index-browser.js", - "./lib/transform-file.js": "./lib/transform-file-browser.js" + "./lib/transform-file.js": "./lib/transform-file-browser.js", + "./src/config/files/index.js": "./src/config/files/index-browser.js", + "./src/transform-file.js": "./src/transform-file-browser.js" }, "dependencies": { "@babel/code-frame": "^7.5.5", diff --git a/scripts/gulp-tasks.js b/scripts/gulp-tasks.js index 73c1f7db2e3f..8118932a8899 100644 --- a/scripts/gulp-tasks.js +++ b/scripts/gulp-tasks.js @@ -11,6 +11,7 @@ * to make standalone builds of other Babel plugins/presets (such as babel-minify) */ +const fs = require("fs"); const path = require("path"); const pump = require("pump"); const chalk = require("chalk"); @@ -24,6 +25,19 @@ const WarningsToErrorsPlugin = require("warnings-to-errors-webpack-plugin"); const webpackStream = require("webpack-stream"); const uglify = require("gulp-uglify"); +function generateResolveAlias() { + const alias = {}; + const packagePath = path.resolve(process.cwd(), "packages"); + fs.readdirSync(packagePath).forEach(folder => { + alias[folder.replace("babel-", "@babel/") + "$"] = path.resolve( + packagePath, + folder, + "src" + ); + }); + return alias; +} + function webpackBuild(opts) { const plugins = opts.plugins || []; let babelVersion = require("../packages/babel-core/package.json").version; @@ -71,7 +85,6 @@ function webpackBuild(opts) { }), new webpack.DefinePlugin({ "process.env.NODE_ENV": '"production"', - "process.env": JSON.stringify({ NODE_ENV: "production" }), BABEL_VERSION: JSON.stringify(babelVersion), VERSION: JSON.stringify(version), }), @@ -82,6 +95,8 @@ function webpackBuild(opts) { new webpack.optimize.ModuleConcatenationPlugin(), ].concat(plugins), resolve: { + //todo: remove resolve.alias when babel packages offer ESModule entry + alias: generateResolveAlias(), plugins: [ // Dedupe packages that are used across multiple plugins. // This replaces DedupePlugin from Webpack 1.x