From 88291f08a8f7d293abf8b4f1ddf79cab6213788a Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Wed, 8 Nov 2017 16:06:28 -0800 Subject: [PATCH 1/2] 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 --- dindctl | 2 +- package.json | 6 ++-- webpack.config.js | 77 ++++++++++++++++++++++++++--------------------- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/dindctl b/dindctl index 382e008d..13a711c1 100755 --- a/dindctl +++ b/dindctl @@ -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 } diff --git a/package.json b/package.json index ece584b9..96756542 100644 --- a/package.json +++ b/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/webpack.config.js b/webpack.config.js index d2347d03..c440344c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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 + }; +} From 2882b97bcd7b1450565d042606dafa4570c0b473 Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Thu, 9 Nov 2017 04:13:42 +0000 Subject: [PATCH 2/2] v6.4.5 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b12053..ecd1de60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v6.4.5 - 2017-11-09 + +* Use uglifyjs-webpack-plugin ^1.0.1 to optimize the supervisor code #524 [Pablo Carranza Velez] + ## v6.4.4 - 2017-11-08 * Dindctl: Use balena to refresh the supervisor container #523 [Pablo Carranza Velez] diff --git a/package.json b/package.json index 96756542..6ead7131 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "resin-supervisor", "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.", - "version": "6.4.4", + "version": "6.4.5", "license": "Apache-2.0", "repository": { "type": "git", @@ -59,4 +59,4 @@ "versionist": "^2.8.0", "webpack": "^3.0.0" } -} +} \ No newline at end of file