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 path = require("path");
const webpack = require("webpack"); 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 = { module.exports = {
entry: "./src/Index.tsx", entry: "./src/Index.tsx",
@ -17,15 +28,15 @@ module.exports = {
'react-native-sqlite-storage': 'react-native-sqlite-storage' 'react-native-sqlite-storage': 'react-native-sqlite-storage'
}, },
plugins: [ plugins: [
new webpack.ProvidePlugin({ new webpack.DefinePlugin({
process: 'process/browser', 'process': {
}), 'env': {
// new webpack.DefinePlugin({ ...readEnvFile('../Common/.env'),
// "process.env.hello": JSON.stringify(true), ...readEnvFile('../CommonUI/.env'),
// }), ...readEnvFile('./.env')
// new Dotenv({ path: '../Common/.env' }), }
// new Dotenv({ path: '../CommonUI/.env'}), }
// new Dotenv({ path: './.env'}) }),
], ],
module: { module: {
rules: [ rules: [

View File

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