From c4740f9b0d1c26ff18f77545c0c1cf948d068cf1 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Tue, 7 Sep 2021 19:21:25 +0300 Subject: [PATCH] config --- config.js | 10 +++++++++- webpack.config.prod.js | 22 +++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/config.js b/config.js index 5f64db1..9373bf9 100644 --- a/config.js +++ b/config.js @@ -4,4 +4,12 @@ const dev = { REVERSE_PROXY_DOCS_URL: "https://toodle.ddns.net/docs/books/reverse-proxy" }; -module.exports = { dev }; +const prod = { + NODE_ENV: "production", + PUBLIC_URL: "/reverse-proxy", + REVERSE_PROXY_API_URL: "https://toodle.ddns.net/reverse-proxy-api", + CHATBOT_API_URL: "https://toodle.ddns.net/chatbot-api", + REVERSE_PROXY_DOCS_URL: "https://toodle.ddns.net/docs/books/reverse-proxy" +}; + +module.exports = { dev, prod }; diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 0275ec0..1b36d03 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -4,9 +4,15 @@ const HtmlWebpackPlugin = require("html-webpack-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const webpackBundleAnalyzer = require("webpack-bundle-analyzer"); const CopyPlugin = require("copy-webpack-plugin"); +const config = require("./config"); -process.env.NODE_ENV = "production"; -process.env.PUBLIC_URL = "/reverse-proxy"; +process.env.NODE_ENV = config.prod.NODE_ENV; +process.env.PUBLIC_URL = config.prod.PUBLIC_URL; + +let configs = {}; +Object.keys(config.dev).forEach(z => { + configs[`process.env.${z}`] = JSON.stringify(config.dev[z]); +}); module.exports = { mode: "production", @@ -26,17 +32,7 @@ module.exports = { filename: "[name].[contenthash].css" }), - new webpack.DefinePlugin({ - // This global makes sure React is built in prod mode. - "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV), - "process.env.PUBLIC_URL": JSON.stringify(process.env.PUBLIC_URL), - "process.env.REVERSE_PROXY_API_URL": JSON.stringify( - "https://toodle.ddns.net/reverse-proxy-api" - ), - "process.env.CHATBOT_API_URL": JSON.stringify( - "https://toodle.ddns.net/chatbot-api" - ) - }), + new webpack.DefinePlugin(configs), new HtmlWebpackPlugin({ template: "src/index.html", favicon: "src/favicon.ico",