Fix babel-standalone for realz (#6137)
* Fix babel-standalone * Fix infinite loop in Makefile (oops) * Override Node.js module resolution to handle babel-core
This commit is contained in:
6
packages/babel-standalone/Gulpfile.js
Normal file
6
packages/babel-standalone/Gulpfile.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const registerBabelStandaloneTask = require("./src/gulpTasks")
|
||||
.registerBabelStandaloneTask;
|
||||
const gulp = require("gulp");
|
||||
|
||||
const version = require("./package.json").version;
|
||||
registerBabelStandaloneTask(gulp, "babel", "Babel", __dirname, version);
|
||||
@@ -4,8 +4,14 @@
|
||||
* compilation of all the JavaScript files. This is because it targets web
|
||||
* browsers, so more transforms are needed than the regular Babel builds that
|
||||
* only target Node.js.
|
||||
*
|
||||
* The tasks in this file are designed to be reusable, so that they can be used
|
||||
* to make standalone builds of other Babel plugins/presets (such as babel-minify)
|
||||
*/
|
||||
|
||||
// Must run first
|
||||
require("./overrideModuleResolution")();
|
||||
|
||||
const pump = require("pump");
|
||||
const rename = require("gulp-rename");
|
||||
const RootMostResolvePlugin = require("webpack-dependency-suite").RootMostResolvePlugin;
|
||||
@@ -100,24 +106,27 @@ function webpackBuild(filename, libraryName, version) {
|
||||
});*/
|
||||
}
|
||||
|
||||
function registerGulpTasks(gulp) {
|
||||
gulp.task("build-babel-standalone", ["build"], cb => {
|
||||
function registerBabelStandaloneTask(gulp, name, exportName, path, version) {
|
||||
gulp.task("build-" + name + "-standalone", cb => {
|
||||
pump(
|
||||
[
|
||||
gulp.src(__dirname + "/index.js"),
|
||||
gulp.src(path + "/src/index.js"),
|
||||
webpackBuild(
|
||||
"babel.js",
|
||||
"Babel",
|
||||
require(__dirname + "/../package.json").version
|
||||
name + ".js",
|
||||
exportName,
|
||||
version
|
||||
),
|
||||
gulp.dest(__dirname + "/../"),
|
||||
gulp.dest(path),
|
||||
uglify(),
|
||||
rename({ extname: ".min.js" }),
|
||||
gulp.dest(__dirname + "/../"),
|
||||
gulp.dest(path),
|
||||
],
|
||||
cb
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = registerGulpTasks;
|
||||
module.exports = {
|
||||
webpackBuild: webpackBuild,
|
||||
registerBabelStandaloneTask: registerBabelStandaloneTask,
|
||||
}
|
||||
|
||||
24
packages/babel-standalone/src/overrideModuleResolution.js
Normal file
24
packages/babel-standalone/src/overrideModuleResolution.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* babel-loader causes problems as it's not part of the monorepo. It pulls in
|
||||
* an older version of babel-core (the version referenced by the root
|
||||
* package.json), rather than the version of babel-core that's in the repo. The
|
||||
* only way to solve this without moving babel-loader into the monorepo is to
|
||||
* override Node's module resolution algorithm to specify a custom resolver for
|
||||
* babel-core to *force* it to use our version.
|
||||
*
|
||||
* Here be dragons.
|
||||
*/
|
||||
|
||||
const Module = require("module");
|
||||
|
||||
module.exports = function overrideModuleResolution() {
|
||||
const originalLoader = Module._load.bind(Module);
|
||||
|
||||
Module._load = function babelStandaloneLoader(request, parent, isMain) {
|
||||
// Redirect babel-core to version in the repo.
|
||||
if (request === "babel-core") {
|
||||
request = __dirname + "/../../babel-core";
|
||||
}
|
||||
return originalLoader(request, parent, isMain);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user