From 21b1ed829c70987d2093cfd2770bc9d6c608df94 Mon Sep 17 00:00:00 2001 From: Yannis Barlas <yannisbarlas@gmail.com> Date: Mon, 1 Feb 2021 16:08:42 +0200 Subject: [PATCH] fix(*): pass client variables to build in production --- Dockerfile-production | 6 ++++++ docker-compose.production.yml | 3 +++ docker-compose.yml | 2 +- webpack/plugins.js | 16 +++++++++++----- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Dockerfile-production b/Dockerfile-production index 57dc80537a..b674453e48 100644 --- a/Dockerfile-production +++ b/Dockerfile-production @@ -22,11 +22,17 @@ ARG node_env ARG server_protocol ARG server_host ARG server_port +ARG client_protocol +ARG client_host +ARG client_port ENV NODE_ENV=$node_env ENV SERVER_PROTOCOL=$server_protocol ENV SERVER_HOST=$server_host ENV SERVER_PORT=$server_port +ENV CLIENT_PROTOCOL=$client_protocol +ENV CLIENT_HOST=$client_host +ENV CLIENT_PORT=$client_port RUN yarn pubsweet build diff --git a/docker-compose.production.yml b/docker-compose.production.yml index c384fe6f56..93fd322294 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -11,6 +11,9 @@ services: - server_protocol=${SERVER_PROTOCOL} - server_host=${SERVER_HOST} - server_port=${SERVER_PORT} + - client_protocol=${CLIENT_PROTOCOL} + - client_host=${CLIENT_HOST} + - client_port=${CLIENT_PORT} ports: - ${SERVER_PORT:-3000}:${SERVER_PORT:-3000} environment: diff --git a/docker-compose.yml b/docker-compose.yml index 661d365e11..a9e21fb04a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,7 +21,7 @@ services: - CLIENT_PORT=${CLIENT_PORT:-4000} - SERVER_PROTOCOL=http - SERVER_HOST=server - - SERVER_PORT=3000 + - SERVER_PORT=${SERVER_PORT:-3000} volumes: - ./app:/home/node/app/app - ./config:/home/node/app/config diff --git a/webpack/plugins.js b/webpack/plugins.js index 9a2c296752..c0c78395ce 100644 --- a/webpack/plugins.js +++ b/webpack/plugins.js @@ -5,8 +5,8 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin') const CopyWebpackPlugin = require('copy-webpack-plugin') const CompressionPlugin = require('compression-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin') -const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') - .BundleAnalyzerPlugin +// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') +// .BundleAnalyzerPlugin module.exports = (opts = {}) => { const plugins = [] @@ -38,9 +38,15 @@ module.exports = (opts = {}) => { } plugins.push( - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': `"${opts.env}"`, - }), + new webpack.EnvironmentPlugin([ + 'NODE_ENV', + 'SERVER_PROTOCOL', + 'SERVER_HOST', + 'SERVER_PORT', + 'CLIENT_PROTOCOL', + 'CLIENT_HOST', + 'CLIENT_PORT', + ]), ) // put dynamically required modules into the build -- GitLab