From 4b771f2f78c0c3fe3d04eab64b93aabe576c0e8b Mon Sep 17 00:00:00 2001 From: FALSAL Date: Thu, 25 Jan 2024 18:04:54 +0100 Subject: [PATCH] emulate obias changes in commit #169 --- package.json | 1 + src/axios.js | 2 +- webpack.config.js | 2 +- webpack.config_uat.js | 102 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 webpack.config_uat.js diff --git a/package.json b/package.json index 96c9fa30..b4115aa2 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "scripts": { "generate-meta-tag": "node ./node_modules/react-cache-buster/dist/generate-meta-tag.js", "start": "webpack serve --mode development --port 3000 --open --hot --progress --host localhost --static .", + "start-remote-api": "webpack serve --config webpack.config_uat.js --mode development --port 3000 --open --hot --progress --host localhost --static .", "build": "npm run generate-meta-tag && npm run build-app", "build-app": "webpack --config webpack.config_prod.js", "test": "react-scripts test", diff --git a/src/axios.js b/src/axios.js index 7216bab4..5568fa54 100644 --- a/src/axios.js +++ b/src/axios.js @@ -2,7 +2,7 @@ var axios = require("axios"); export const baseURL = // "https://www2.zuugle.at/api"; window.location.host.indexOf("localhost") >= 0 - ? "http://localhost:8080/api" + ? process.env.REACT_APP_API_URL : `${window.location.protocol}//${window.location.host}/api`; let axiosInstance = axios.create({ diff --git a/webpack.config.js b/webpack.config.js index ee86d070..34b4d06c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -96,7 +96,7 @@ module.exports = { attributes: {}, }), new webpack.DefinePlugin({ - "process.env.API_URL": JSON.stringify("http://localhost:8080/api"), + "process.env.REACT_APP_API_URL": JSON.stringify("http://localhost:8080/api"), }), ], }; diff --git a/webpack.config_uat.js b/webpack.config_uat.js new file mode 100644 index 00000000..715719d1 --- /dev/null +++ b/webpack.config_uat.js @@ -0,0 +1,102 @@ +const webpack = require("webpack"); +const path = require("path"); +const HtmlWebpackPlugin = require("html-webpack-plugin"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const MiniCssExtractPlugin = require("mini-css-extract-plugin"); + +const BUILD_DIR = path.resolve(__dirname, "build"); + +module.exports = { + mode: "development", + output: { + path: BUILD_DIR, + filename: "./app_static/[name].bundle.js", + }, + + devServer: { + static: BUILD_DIR, + // directory: BUILD_DIR, + // staticOptions: { + // setHeaders: (res, path) => { + // if (path.endsWith('.json')) { + // res.setHeader('Content-Type', 'application/javascript'); + // } + // }, + // }, + // staticOptions: { + // setHeaders: (res, path) => { + // if (path.endsWith('.json')) { + // res.setHeader('Content-Type', 'text/html'); + // } + // }, + // }, + + compress: true, + open: true, + historyApiFallback: true, + }, + module: { + rules: [ + { + test: /\.(js|jsx)$/, + exclude: /node_modules/, + use: { + loader: "babel-loader", + options: { + presets: [["@babel/preset-env", { targets: "defaults" }]], + }, + }, + }, + { + test: /\.html$/, + loader: "html-loader", + }, + { + test: /\.(scss)$/, + loader: "css-loader", + }, + { + test: /\.css$/i, + use: [MiniCssExtractPlugin.loader, "css-loader"], + }, + { + test: /\.svg$/i, + issuer: /\.[jt]sx?$/, + use: ["@svgr/webpack", "url-loader"], + }, + { + test: /\.(png|jpg|jpeg|gif|ico)$/, + use: [ + { + loader: "file-loader", + options: { + name: "./img/[name].[hash].[ext]", + }, + }, + ], + }, + { + test: /\.js$/, + enforce: "pre", + use: ["source-map-loader"], + }, + ], + }, + plugins: [ + new webpack.HotModuleReplacementPlugin(), + new HtmlWebpackPlugin({ + inject: true, + template: "./public/index.html", + }), + new CopyWebpackPlugin({ + patterns: [{ from: "./public", to: "app_static" }], + }), + new MiniCssExtractPlugin({ + filename: "./app_static/[name].styles.css", + attributes: {}, + }), + new webpack.DefinePlugin({ + "process.env.REACT_APP_API_URL": JSON.stringify("https://www2.zuugle.at/api"), + }), + ], +};