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 + }; +}