From c6cff7a0c4f740fc7f3476ea305d395c9921b2a9 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Sun, 14 Aug 2022 21:05:45 +0200 Subject: [PATCH] If .env is not defined use sane defaults from .env.example --- src/config.ts.example | 5 ----- webpack.config.js | 16 ++++++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) delete mode 100644 src/config.ts.example diff --git a/src/config.ts.example b/src/config.ts.example deleted file mode 100644 index 687ef40..0000000 --- a/src/config.ts.example +++ /dev/null @@ -1,5 +0,0 @@ -{ - "SEASONED_URL": "http://localhost:31459/api/", - "ELASTIC_URL": "http://localhost:9200", - "ELASTIC_INDEX": "shows,movies" -} diff --git a/webpack.config.js b/webpack.config.js index 32314bf..e165f8d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,21 +5,21 @@ const HTMLWebpackPlugin = require("html-webpack-plugin"); const { VueLoaderPlugin } = require("vue-loader"); const TerserPlugin = require("terser-webpack-plugin"); const dotenv = require("dotenv").config({ path: "./.env" }); +const dotenvExample = require("dotenv").config({ path: "./.env.example" }); const sourcePath = path.resolve(__dirname, "src"); const indexFile = path.join(sourcePath, "index.html"); const javascriptEntry = path.join(sourcePath, "main.ts"); const publicPath = path.resolve(__dirname, "public"); const isProd = process.env.NODE_ENV === "production"; +const variables = dotenv.parsed || dotenvExample.parsed; // Merge inn all process.env values that match dotenv keys -if (dotenv.parsed) { - Object.keys(process.env).forEach(key => { - if (key in dotenv.parsed) { - dotenv.parsed[key] = process.env[key]; - } - }); -} +Object.keys(process.env).forEach(key => { + if (key in variables) { + variables[key] = process.env[key]; + } +}); module.exports = { mode: process.env.NODE_ENV, @@ -79,7 +79,7 @@ module.exports = { minify: isProd }), new webpack.DefinePlugin({ - "process.env": JSON.stringify(dotenv.parsed) + "process.env": JSON.stringify(variables) }) ], resolve: {