Skip to content

Commit b7cb9a7

Browse files
claudertibbles
authored andcommitted
Fix core-js duplication in viewer bundles
Updated kolibri-sandbox to use Babel's useBuiltIns: 'usage' instead of explicit core-js imports. This eliminates ~330 KB of duplication across bloompub_viewer, html5_viewer, and learn.app bundles. Changes: - Set babel useBuiltIns to 'usage' with corejs 3.46 - Removed explicit core-js imports from iframe.js and xAPI files - Babel now auto-injects polyfills only during standalone build - When imported into main bundles, no core-js duplication occurs Expected savings: ~330 KB across 3 viewer bundles
1 parent c3b7f82 commit b7cb9a7

File tree

6 files changed

+44
-16
lines changed

6 files changed

+44
-16
lines changed

packages/kolibri-sandbox/babel.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = {
33
[
44
'@babel/preset-env',
55
{
6-
useBuiltIns: false,
6+
useBuiltIns: 'usage',
7+
corejs: '3.46',
78
},
89
],
910
],

packages/kolibri-sandbox/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@
1313
"author": "Learning Equality",
1414
"license": "MIT",
1515
"devDependencies": {
16+
"babel-loader": "^10.0.0",
17+
"css-loader": "7.1.2",
18+
"css-minimizer-webpack-plugin": "7.0.2",
1619
"eslint-plugin-compat": "^6.0.2",
1720
"html-webpack-plugin": "5.6.5",
1821
"jquery": "3.5.1",
1922
"jszip": "^3.10.1",
23+
"mini-css-extract-plugin": "^2.9.4",
2024
"mutationobserver-shim": "^0.3.7",
21-
"purgecss": "^6.0.0"
25+
"purgecss": "^6.0.0",
26+
"terser-webpack-plugin": "^5.3.14",
27+
"webpack": "^5.103.0"
2228
},
2329
"dependencies": {
2430
"core-js": "3.47",
2531
"dayjs": "^1.11.19",
2632
"iri": "^1.3.1",
2733
"is-language-code": "^3.1.0",
2834
"iso8601-duration": "^2.1.3",
35+
"lodash": "^4.17.21",
2936
"toposort-class": "^1.0.1",
3037
"uuid": "^13.0.0"
3138
},

packages/kolibri-sandbox/src/iframe.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
import 'core-js/es/array/includes';
2-
import 'core-js/es/object/assign';
3-
import 'core-js/es/object/entries';
4-
import 'core-js/es/object/values';
5-
import 'core-js/es/promise';
6-
import 'core-js/es/string/starts-with';
7-
import 'core-js/web/url';
81
import Sandbox from './iframeClient';
92

103
const sandbox = new Sandbox();

packages/kolibri-sandbox/src/xAPI/xAPIConstants.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* xAPI Constants
33
*/
44

5-
import 'core-js/features/set';
6-
75
export const OBJECT_TYPES = {
86
AGENT: 'Agent',
97
GROUP: 'Group',

packages/kolibri-sandbox/src/xAPI/xAPISchema.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* For more information, see:
55
* https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md
66
*/
7-
import 'core-js/features/set';
87
import isArray from 'lodash/isArray';
98
import isBoolean from 'lodash/isBoolean';
109
import isFunction from 'lodash/isFunction';

packages/kolibri-sandbox/webpack.config.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const path = require('path');
22
const fs = require('fs');
3+
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
4+
const TerserPlugin = require('terser-webpack-plugin');
35
const HtmlWebpackPlugin = require('html-webpack-plugin');
46

57
function Plugin() {}
@@ -30,23 +32,51 @@ module.exports = {
3032
entry: path.resolve(__dirname, './src/iframe.js'),
3133
output: {
3234
filename: 'sandbox-[contenthash].js',
33-
chunkFilename: '[name]-[contenthash].bundle.js',
35+
chunkFilename: 'sandbox-[name]-[contenthash].bundle.js',
3436
path: path.resolve(__dirname, '../../kolibri/core/content/static/sandbox'),
3537
},
36-
mode: 'none',
38+
mode: 'production',
3739
module: {
3840
rules: [
3941
{
40-
test: /\.js$/,
42+
test: /\.(js|mjs)$/,
4143
loader: 'babel-loader',
42-
exclude: { and: [/(uuid|core-js)/, { not: [/\.(esm\.js|mjs)$/] }] },
44+
exclude: [
45+
// From: https://webpack.js.org/loaders/babel-loader/#exclude-libraries-that-should-not-be-transpiled
46+
// \\ for Windows, / for macOS and Linux
47+
/node_modules[\\/]core-js/,
48+
/node_modules[\\/]webpack[\\/]buildin/,
49+
],
50+
options: {
51+
// Let babel auto-detect ES vs CommonJS
52+
sourceType: 'unambiguous',
53+
},
4354
},
4455
],
4556
},
4657
optimization: {
4758
splitChunks: {
4859
minChunks: 2,
4960
},
61+
minimizer: [
62+
new TerserPlugin({
63+
parallel: true,
64+
terserOptions: {
65+
mangle: {
66+
safari10: true,
67+
},
68+
safari10: true,
69+
output: {
70+
comments: false,
71+
},
72+
},
73+
}),
74+
new CssMinimizerPlugin({
75+
minimizerOptions: {
76+
preset: ['default', { reduceIdents: false, zindex: false }],
77+
},
78+
}),
79+
],
5080
},
5181
plugins: [
5282
new Plugin(),

0 commit comments

Comments
 (0)