Skip to content

Commit eedd17d

Browse files
committed
refactor(theme): replace browserify/watchify/terser with webpack
The JS build toolchain has been migrated from browserify + babelify + watchify + terser to webpack + babel-loader. This eliminates several unmaintained or deprecated packages and resolves a Dependabot security alert for a vulnerable transitive dependency (elliptic 6.6.1), which was introduced via browserify and watchify. Removed packages: - browserify: largely unmaintained, last release Oct 2024, 346 open issues. Was the root cause of the elliptic vulnerability alert. - babelify: the browserify transform for Babel, no longer needed. - watchify: effectively unmaintained since Jan 2021. Also introduced elliptic via its own dependency chain. - terser: standalone minifier, now replaced by webpack's built-in TerserPlugin with equivalent compression settings. Added packages: - webpack + webpack-cli Replaces watchify and minification. - babel-loader: the webpack equivalent of babelify, connects webpack to the existing Babel configuration. The webpack.config.js mirrors the previous build behaviour: - Production mode outputs application.min.js with the same Terser compression settings as the old .terserrc.json Browser compatibility is preserved. Previously, Babel targets were set explicitly in .babelrc as ">0.25%". With webpack + babel-loader, Babel automatically reads the existing .browserslistrc file, so babel output should be similar to the old setup. .babelrc has been simplified accordingly
1 parent 0358f94 commit eedd17d

5 files changed

Lines changed: 624 additions & 1242 deletions

File tree

theme/.babelrc

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
{
2-
"env": {
3-
"development": {
4-
"presets": [
5-
["@babel/preset-env", {
6-
"useBuiltIns": "usage",
7-
"corejs": 3,
8-
"debug": false,
9-
"targets": {
10-
"browsers": [ ">0.25%"]
11-
}
12-
}]
13-
]
14-
},
15-
"test": {
16-
"presets":[
17-
["@babel/preset-env", {
18-
"useBuiltIns": "usage",
19-
"targets": {
20-
"node": "current",
21-
"browsers": [ ">0.25%"]
22-
}
23-
}]
24-
]
25-
}
26-
}
2+
"presets": [
3+
["@babel/preset-env", {
4+
"useBuiltIns": "usage",
5+
"corejs": 3,
6+
"debug": false
7+
}]
8+
]
279
}

theme/.terserrc.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

theme/package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@
2020
"build": "node scripts/build.js",
2121
"buildtheme": "yarn build:clean && yarn build:js && yarn build:css && yarn build:copy:base && yarn build:copy:theme",
2222
"build:clean": "rimraf ../public/javascripts/* ../public/stylesheets/*",
23-
"build:js": "mkdir -p ../public/javascripts && yarn build:js:bundle && yarn build:js:minify",
24-
"build:js:bundle": "browserify ${EB_THEME:=openconext}/javascripts/application.js -t [ babelify ] -o ../public/javascripts/application.bundle.js",
25-
"build:js:minify": "terser ../public/javascripts/application.bundle.js --config-file .terserrc.json -o ../public/javascripts/application.min.js",
26-
"build:js:debug": "mkdir -p ../public/javascripts && browserify ${EB_THEME:=openconext}/javascripts/application.js -d -t [ babelify ] -o ../public/javascripts/application.min.js",
23+
"build:js": "mkdir -p ../public/javascripts && EB_THEME=${EB_THEME:=openconext} webpack --config webpack.config.js --mode production",
24+
"build:js:debug": "mkdir -p ../public/javascripts && EB_THEME=${EB_THEME:=openconext} webpack --config webpack.config.js --mode development",
2725
"build:css": "mkdir -p ../public/stylesheets && yarn build:css:sass && yarn build:css:postcss",
2826
"build:css:sass": "sass ${EB_THEME:=openconext}/stylesheets:../public/stylesheets/",
2927
"build:css:postcss": "BROWSERSLIST_CONFIG=.browserslistrc postcss ../public/stylesheets/*.css --use autoprefixer --use cssnano --no-map --dir ../public/stylesheets",
3028
"build:copy:base": "mkdir -p ../public/images && copyfiles --up 2 base/images/* ../public/images/ && mkdir -p ../public/fonts && copyfiles --up 2 -e base/stylesheets/fonts/*.txt -f base/stylesheets/fonts/* ../public/fonts",
3129
"build:copy:theme": "copyfiles --up 2 ${EB_THEME:=openconext}/images/* ../public/images/ && copyfiles --up 2 -e {EB_THEME:=openconext}/stylesheets/fonts/*.txt -f ${EB_THEME:=openconext}/stylesheets/fonts/* ../public/fonts",
3230
"create-theme": "node scripts/create-theme.js",
3331
"watch": "node scripts/watch.js",
34-
"watch:js": "watchify ${EB_THEME:=base}/javascripts/application.js --poll=100 -d -t [ babelify ] -o ../public/javascripts/application.bundle.js -v && cp ../public/javascripts/application.bundle.js ../public/javascripts/application.min.js",
32+
"watch:js": "mkdir -p ../public/javascripts && EB_THEME=${EB_THEME:=openconext} webpack --config webpack.config.js --mode development --watch",
3533
"watch:css": "sass -w ${EB_THEME:=openconext}/stylesheets:../public/stylesheets",
3634
"release": "yarn build"
3735
},
@@ -41,8 +39,7 @@
4139
"@babel/preset-env": "^7.22",
4240
"@eslint/js": "^10.0.1",
4341
"autoprefixer": "^10.4",
44-
"babelify": "^10.0",
45-
"browserify": "^17.0",
42+
"babel-loader": "^9.0",
4643
"copyfiles": "^2.4",
4744
"core-js": "^3.32",
4845
"cssnano": "^7.1.1",
@@ -57,8 +54,9 @@
5754
"socket.io": "^4.8.1",
5855
"stylelint": "^17.4.0",
5956
"stylelint-config-recommended": "^18.0.0",
60-
"terser": "^5.44.0",
61-
"watchify": "^4.0.0"
57+
"terser-webpack-plugin": "^5.4.0",
58+
"webpack": "^5.0",
59+
"webpack-cli": "^5.0"
6260
},
6361
"dependencies": {
6462
"@fortawesome/fontawesome-free": "^7.0.1",

theme/webpack.config.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const path = require('path');
2+
const TerserPlugin = require('terser-webpack-plugin');
3+
4+
const theme = process.env.EB_THEME || 'openconext';
5+
6+
module.exports = (env, argv) => {
7+
const isProd = argv.mode === 'production';
8+
9+
return {
10+
entry: path.resolve(__dirname, `${theme}/javascripts/application.js`),
11+
output: {
12+
path: path.resolve(__dirname, '../public/javascripts'),
13+
filename: 'application.min.js',
14+
},
15+
module: {
16+
rules: [
17+
{
18+
test: /\.js$/,
19+
exclude: /node_modules/,
20+
use: {
21+
loader: 'babel-loader',
22+
},
23+
},
24+
],
25+
},
26+
optimization: isProd ? {
27+
minimizer: [
28+
new TerserPlugin({
29+
terserOptions: {
30+
compress: {
31+
passes: 2,
32+
inline: 1,
33+
dead_code: true,
34+
unused: false,
35+
reduce_funcs: false,
36+
reduce_vars: false,
37+
},
38+
mangle: true,
39+
},
40+
}),
41+
],
42+
} : {},
43+
devtool: isProd ? false : 'source-map',
44+
};
45+
};

0 commit comments

Comments
 (0)