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:
committed by
Nicolò Ribaudo
parent
cc51f2a1f2
commit
683adcbb70
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user