make env files work

This commit is contained in:
Simon Larsen 2022-05-24 11:54:21 +01:00
parent 3fb255721a
commit b1d7649b17
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
2 changed files with 23 additions and 13 deletions

View File

@ -1,6 +1,17 @@
const path = require("path");
const webpack = require("webpack");
const Dotenv = require('dotenv-webpack');
const dotenv = require('dotenv');
const readEnvFile = (pathToFile) => {
const parsed = dotenv.config({ path: pathToFile }).parsed;
const env = {};
for (const key in parsed) {
env[key] = JSON.stringify(parsed[key]);
}
return env;
}
module.exports = {
entry: "./src/Index.tsx",
@ -17,15 +28,15 @@ module.exports = {
'react-native-sqlite-storage': 'react-native-sqlite-storage'
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
// new webpack.DefinePlugin({
// "process.env.hello": JSON.stringify(true),
// }),
// new Dotenv({ path: '../Common/.env' }),
// new Dotenv({ path: '../CommonUI/.env'}),
// new Dotenv({ path: './.env'})
new webpack.DefinePlugin({
'process': {
'env': {
...readEnvFile('../Common/.env'),
...readEnvFile('../CommonUI/.env'),
...readEnvFile('./.env')
}
}
}),
],
module: {
rules: [

View File

@ -4,9 +4,8 @@ import Route from 'Common/Types/API/Route';
import Version from 'Common/Types/Version';
import URL from 'Common/Types/API/URL'
export const env: Function = (_key: string): string => {
console.log(process.env['production']);
return ''
export const env: Function = (key: string): string => {
return process.env[key] || '';
};
export const API_PROTOCOL: Protocol = window.location.protocol.includes('https')