passing configuration through webpack

This commit is contained in:
Fran Jurmanović
2021-06-05 13:13:39 +02:00
parent 67eda03307
commit 4ed0b75b09
5 changed files with 20 additions and 8 deletions

8
declaration.d.ts vendored
View File

@@ -1 +1,9 @@
declare module "*.scss";
declare var __CONFIG__: SettingType;
type SettingType = {
apiUrl: string;
apiVersion: string;
ssl: string;
appName: string;
};

View File

@@ -132,7 +132,7 @@ class AppMenuElement extends BaseComponentElement {
return html`
<div data-target="app-menu.sidebar">
${menuHeader("Wallets")} ${regularMenu("/", "Home")}
${menuHeader(__CONFIG__.appName)} ${regularMenu("/", "Home")}
${authMenu("/history", "Transaction History")}
${authMenu(
"/wallet/all",

View File

@@ -1,5 +1,6 @@
{
"apiUrl": "main-wallet--dtnyc2vcdgu2re9j-gtw.qovery.io",
"apiUrl": "localhost:4000",
"apiVersion": "v1",
"ssl": true
"ssl": false,
"appName": "Wallets"
}

View File

@@ -1,11 +1,9 @@
import settings from "configs/development/app-settings.json";
class HttpClient {
private url: string;
constructor() {
this.url = `${settings.ssl ? "https" : "http"}://${settings.apiUrl}/${
settings.apiVersion
}`;
this.url = `${__CONFIG__.ssl ? "https" : "http"}://${
__CONFIG__.apiUrl
}/${__CONFIG__.apiVersion}`;
}
post(url: string, data: Object, headersParam: HeadersInit): Promise<any> {

View File

@@ -1,5 +1,7 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const settings = require("./src/configs/development/app-settings.json");
const { DefinePlugin } = require('webpack');
const alias = {
common: path.resolve(__dirname, '/common'),
@@ -83,6 +85,9 @@ module.exports = {
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new DefinePlugin({
__CONFIG__: JSON.stringify(settings)
})
],
resolve: {
extensions: ['.js', '.ts'],