Use uglifyjs-webpack-plugin ^1.0.1 to optimize the supervisor code

We've been using UglifyJS 0.4.6 (the webpack default) so far, but this doesn't support ES6 and some dependency
updates are starting to cause builds to break (e.g. https://github.com/request/request/issues/2772, which also happens to break
my builds in the multicontainer branch).

Here we switch to the latest uglifyjs-webpack-plugin which is designed for ES2015 support.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2017-11-08 16:06:28 -08:00
parent 62cf72bf03
commit 88291f08a8
3 changed files with 46 additions and 39 deletions

View File

@ -118,7 +118,7 @@ function buildSupervisorSrc {
( 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 )
( cd "$SUPERVISOR_BASE_DIR" && npm install && npm run build -- --env.noOptimize )
fi
}

View File

@ -9,8 +9,7 @@
},
"scripts": {
"start": "./entry.sh",
"build": "webpack --optimize-minimize",
"build-no-optimize": "webpack",
"build": "webpack",
"lint": "resin-lint src/",
"versionist": "versionist"
},
@ -56,7 +55,8 @@
"semver": "^5.3.0",
"semver-regex": "^1.0.0",
"typed-error": "~0.1.0",
"uglifyjs-webpack-plugin": "^1.0.1",
"versionist": "^2.8.0",
"webpack": "^3.0.0"
}
}
}

View File

@ -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 UglifyPlugin = require("uglifyjs-webpack-plugin");
var externalModules = [
'mkfifo',
@ -49,41 +50,47 @@ externalModules.push(new RegExp('^(' + _.reject(maybeOptionalModules, requiredMo
console.log('Using the following dependencies as external:', externalModules);
module.exports = {
entry: './src/app.coffee',
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'dist')
},
resolve: {
extensions: [".js", ".json", ".coffee"]
},
target: 'node',
module: {
rules: [
{
test: /JSONStream\/index\.js$/,
use: require.resolve('./fix-jsonstream')
},
{
test: /\.coffee$/,
use: require.resolve('coffee-loader')
}
]
},
externals: (context, request, callback) => {
for (let m of externalModules) {
if ((typeof m === 'string' && m === request) || (m instanceof RegExp && m.test(request))) {
return callback(null, 'commonjs ' + request);
} else if (typeof m != 'string' && !(m instanceof RegExp)) {
throw new Error('Invalid entry in external modules: ' + m);
}
}
return callback()
},
plugins: [
module.exports = function (env) {
let plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
})
]
};
if (env == null || !env.noOptimize) {
plugins.push(new UglifyPlugin())
}
return {
entry: './src/app.coffee',
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'dist')
},
resolve: {
extensions: [".js", ".json", ".coffee"]
},
target: 'node',
module: {
rules: [
{
test: /JSONStream\/index\.js$/,
use: require.resolve('./fix-jsonstream')
},
{
test: /\.coffee$/,
use: require.resolve('coffee-loader')
}
]
},
externals: (context, request, callback) => {
for (let m of externalModules) {
if ((typeof m === 'string' && m === request) || (m instanceof RegExp && m.test(request))) {
return callback(null, 'commonjs ' + request);
} else if (typeof m != 'string' && !(m instanceof RegExp)) {
throw new Error('Invalid entry in external modules: ' + m);
}
}
return callback()
},
plugins: plugins
};
}