Reduce standalone build size (#10668)
* infra: build standalone against src * infra: add absoluteRuntime # Conflicts: # babel.config.js * chore: remove `process.env` replace * add $ to signify exact match credits to Nicolò
This commit is contained in:
parent
cc51f2a1f2
commit
683adcbb70
@ -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,
|
||||
@ -125,10 +137,7 @@ module.exports = function(api) {
|
||||
],
|
||||
plugins: [
|
||||
includeRuntime
|
||||
? [
|
||||
"@babel/transform-runtime",
|
||||
{ version: require("@babel/runtime/package").version },
|
||||
]
|
||||
? ["@babel/transform-runtime", transformRuntimeOpts]
|
||||
: null,
|
||||
].filter(Boolean),
|
||||
},
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user