Skip to content

Commit

Permalink
chore: stub out browserslist an tr46 packages MONGOSH-1335 (#1397)
Browse files Browse the repository at this point in the history
Both of these packages add nontrivial amounts of code
to our bundles without providing additional value to mongosh.

Therefore, we stub these out and save about 50 % of our bundle
size and shave off about 10 % of startup duration.
  • Loading branch information
addaleax authored Jan 31, 2023
1 parent 85f6dac commit 87f058f
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 1 deletion.
17 changes: 16 additions & 1 deletion config/webpack.base.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

/** @type import('webpack').Configuration */
module.exports = {
Expand All @@ -14,7 +16,13 @@ module.exports = {
},

resolve: {
extensions: ['.ts', '.js']
extensions: ['.ts', '.js'],
alias: {
// Stub out particularly large dependencies that are unnecessary and/or
// only provide features that Node.js also provides out of the box.
browserslist: path.resolve(__dirname, '..', 'scripts', 'dummy-browserslist.js'),
tr46: path.resolve(__dirname, '..', 'scripts', 'tr46-stub.js')
}
},

optimization: {
Expand Down Expand Up @@ -44,4 +52,11 @@ module.exports = {

node: false,
target: 'node',

plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false
})
]
};
225 changes: 225 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"terser-webpack-plugin": "^4.2.3",
"ts-loader": "^8.0.14",
"webpack": "^5.75.0",
"webpack-bundle-analyzer": "^4.7.0",
"webpack-cli": "^4.3.1",
"webpack-merge": "^5.8.0"
}
Expand Down
9 changes: 9 additions & 0 deletions scripts/dummy-browserslist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';
// Babel has a dependency on browserslist (and in particular,
// caniuse-lite through browserslist, which is a fairly large
// npm package). However, the way in which we use babel does
// not actually require browserslist support, so we can safely
// stub this away.
module.exports = () => {
throw new Error('browserslist not supported');
};
Loading

0 comments on commit 87f058f

Please sign in to comment.