support production mode for client build and server

Change-Id: I483f614180505ba3783b4b1e5a7387ce93e2712a
diff --git a/client/webpack.config.js b/client/webpack.config.js
index 841c7d5..eb5c8b9 100644
--- a/client/webpack.config.js
+++ b/client/webpack.config.js
@@ -1,18 +1,32 @@
+'use strict'
 const path = require('path')
+require('dotenv').config({ path: path.resolve(__dirname, '..', '.env') })
 const HtmlWebpackPlugin = require('html-webpack-plugin')
-const webpack = require('webpack')
+const mode = process.env.NODE_ENV || 'development'
+
+let entry = [path.resolve(__dirname, 'src', 'index.js')]
+let plugins = [new HtmlWebpackPlugin({
+    template: path.resolve(__dirname, 'src', 'index.ejs')
+})]
+let devtool = undefined
+
+if (mode === 'development') {
+    const webpack = require('webpack')
+    entry = ['react-hot-loader/patch', 'webpack-hot-middleware/client', ...entry]
+    plugins = [new webpack.HotModuleReplacementPlugin(), ...plugins]
+    devtool = 'inline-source-map'
+}
+console.log(`Webpack configured for ${mode}`)
 
 module.exports = {
-    entry: ['react-hot-loader/patch',
-        'webpack-hot-middleware/client',
-        path.resolve(__dirname, 'src', 'index.js')],
+    entry,
     output: {
         path: path.resolve(__dirname, 'dist'),
         filename: 'bundle.js',
         publicPath: '/'
     },
-    devtool: 'inline-source-map',
-    mode: 'development',
+    devtool,
+    mode,
     module: {
         rules: [
             {
@@ -35,10 +49,5 @@
             }
         ]
     },
-    plugins: [
-        new webpack.HotModuleReplacementPlugin(),
-        new HtmlWebpackPlugin({
-            template: path.resolve(__dirname, 'src', 'index.ejs')
-        })
-    ]
+    plugins
 }
\ No newline at end of file