🔧 Added process.env support via Webpack

This commit is contained in:
2021-10-19 14:32:47 -07:00
parent c1e9a30419
commit 9024c3cce9
3 changed files with 95 additions and 90 deletions

View File

@@ -9,7 +9,7 @@ services:
container_name: threetwo-ui
env_file: ./docker-compose.env
environment:
DOCKERHOST: "{{.Node.Hostname}}"
DOCKER_SOCKET_HOST: "{{.Node.Hostname}}:8051"
restart: unless-stopped
labels:
- "traefik.enable=true"

View File

@@ -8,7 +8,7 @@ import { success } from "react-notification-system-redux";
const WebSocketContext = createContext(null);
export const WebSocketProvider = ({ children }): ReactElement => {
const dispatch = useDispatch();
const socketHost = process.env.DOCKERHOST + ":8051" || SOCKET_BASE_URI;
const socketHost = process.env.DOCKER_SOCKET_HOST || SOCKET_BASE_URI;
const socket: Socket = io(socketHost);
socket.on("connect", () => {

View File

@@ -1,11 +1,13 @@
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require("webpack");
const outputDirectory = "dist";
const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
module.exports = {
module.exports = (env) => {
return {
entry: ["babel-polyfill", "./src/client/index.tsx"],
output: {
path: path.join(__dirname, outputDirectory),
@@ -89,11 +91,14 @@ module.exports = {
title: "express-typescript-react",
}),
new webpack.DefinePlugin({
"process.env.DOCKERHOST": JSON.stringify(process.env.DOCKERHOST),
"process.env.DOCKER_SOCKET_HOST": JSON.stringify(
process.env.DOCKER_SOCKET_HOST,
),
}),
new MiniCssExtractPlugin({
filename: "./css/[name].css",
chunkFilename: "./css/[id].css",
}),
],
};
};