Skip to content

Commit

Permalink
Use babel-minify to optimize the supervisor code
Browse files Browse the repository at this point in the history
We've been using UglifyJS (the webpack default) so far, but this doesn't support ES6 and some dependency
updates are starting to cause builds to break (e.g. request/request#2772, which also happens to break
my builds in the multicontainer branch).

Here we switch to using babel-minify which is designed for ES2015 support. I had to disable the "mangle" option
because some dependencies break when mangled by babel-minify (which is a bit mysterious since it should
be able to handle them well, but there's at least one case where an eval() in a dependency breaks the supervisor).
This adds ~800kB to the resulting uncompressed image.

Since the optimization now happens with a plugin instead of the webpack command line,
we can't do the no-optimize trick we were doing in dindctl now - but it should
also be less important now that we don't mangle names.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
  • Loading branch information
Pablo Carranza Velez committed Nov 9, 2017
1 parent 62cf72b commit e734c14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
13 changes: 2 additions & 11 deletions dindctl
Expand Up @@ -49,7 +49,6 @@ DIST_MOUNTED="false"
DIND_IMAGE="resin-supervisor-dind"
CONTAINER_NAME="resin_supervisor_1"
PRELOADED_IMAGE=""
OPTIMIZE="true"
CONFIG_FILENAME="config.json"

function showHelp {
Expand Down Expand Up @@ -93,9 +92,6 @@ function parseOptions {
ARCH="$2"
shift || { echo "--arch provided not specified" && exit 1; }
;;
--no-optimize)
OPTIMIZE="false"
;;
*)
echo "Warning: unknown argument: $arg"
;;
Expand All @@ -113,13 +109,8 @@ function buildSupervisor {
}

function buildSupervisorSrc {
if [ "$OPTIMIZE" = "true" ]; then
echo "Rebuilding supervisor source"
( cd "$SUPERVISOR_BASE_DIR" && npm install && npm run build )
else
echo "Rebuilding supervisor source without optimizations"
( cd "$SUPERVISOR_BASE_DIR" && npm install && npm run build-no-optimize )
fi
echo "Rebuilding supervisor source"
( cd "$SUPERVISOR_BASE_DIR" && npm install && npm run build )
}

function refreshSupervisorSrc {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -9,8 +9,7 @@
},
"scripts": {
"start": "./entry.sh",
"build": "webpack --optimize-minimize",
"build-no-optimize": "webpack",
"build": "webpack",
"lint": "resin-lint src/",
"versionist": "versionist"
},
Expand All @@ -23,6 +22,7 @@
},
"devDependencies": {
"JSONStream": "^1.1.2",
"babel-minify-webpack-plugin": "^0.2.0",
"blinking": "~0.0.2",
"bluebird": "^3.5.0",
"body-parser": "^1.12.0",
Expand Down Expand Up @@ -59,4 +59,4 @@
"versionist": "^2.8.0",
"webpack": "^3.0.0"
}
}
}
8 changes: 7 additions & 1 deletion webpack.config.js
Expand Up @@ -2,7 +2,8 @@ var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var _ = require('lodash');
var path = require('path')
var path = require('path');
var MinifyPlugin = require("babel-minify-webpack-plugin");

var externalModules = [
'mkfifo',
Expand Down Expand Up @@ -84,6 +85,11 @@ module.exports = {
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
}),
new MinifyPlugin({
mangle: false,
keepFnName: true,
keepClassName: true
})
]
};

0 comments on commit e734c14

Please sign in to comment.