Skip to content

Commit

Permalink
Use uglifyjs-webpack-plugin ^1.0.1 to optimize the supervisor code
Browse files Browse the repository at this point in the history
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. request/request#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>
  • Loading branch information
Pablo Carranza Velez committed Nov 9, 2017
1 parent 62cf72b commit 88291f0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 39 deletions.
2 changes: 1 addition & 1 deletion dindctl
Expand Up @@ -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
}

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 Down Expand Up @@ -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"
}
}
}
77 changes: 42 additions & 35 deletions 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 UglifyPlugin = require("uglifyjs-webpack-plugin");

var externalModules = [
'mkfifo',
Expand Down Expand Up @@ -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
};
}

0 comments on commit 88291f0

Please sign in to comment.